Skip to content

Commit dcc5075

Browse files
author
Lennart Regebro
committed
When saving, exclude_unset doesn't always behave as expected
So we remove exclude_unset, which will increase the size of the output, but that's not big deal.
1 parent a0ad944 commit dcc5075

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Changes
44
1.2.0b3 (unreleased)
55
--------------------
66

7-
- Nothing changed yet.
7+
- Now includes default values when saving, making the OCF files larger.
88

99

1010
1.2.0b2 (2025-02-04)

src/pyocf/captable.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def file_factory(p):
103103
def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
104104
if issuer is None and self.manifest is None:
105105
raise ValueError(
106-
"You must specify an issuer, either by passing the value to the"
106+
"You must specify an issuer, either by passing the value to the "
107107
"save method, or by creating a Manifest."
108108
)
109109

@@ -125,7 +125,7 @@ def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
125125

126126
with file_factory(ocffilename) as ocffile:
127127
itemfile = fileob(items=getattr(self, filetype))
128-
jsonstr = itemfile.json(exclude_unset=True)
128+
jsonstr = itemfile.model_dump_json()
129129
if pretty:
130130
jsonstr = json.dumps(json.loads(jsonstr), indent=4)
131131
jsonstr = jsonstr.encode("UTF-8")
@@ -156,7 +156,7 @@ def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
156156
self.manifest = ocfmanifestfile.OCFManifestFile(**manifest_data)
157157

158158
with file_factory(manifest_path) as ocffile:
159-
jsonstr = self.manifest.json()
159+
jsonstr = self.manifest.model_dump_json()
160160
if pretty:
161161
jsonstr = json.dumps(json.loads(jsonstr), indent=4)
162162
ocffile.write(jsonstr.encode("UTF-8"))

tests/test_save.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ def test_save_directory():
5757
# Do some simple checks on the data
5858
assert b'"file_type": "OCF_MANIFEST_FILE"' in data
5959
assert b'"filepath": "StockLegends.ocf.json",' in data
60+
61+
transactions = [x for x in files if x.name == "Transactions.ocf.json"][0]
62+
data = transactions.open("rb").read()
63+
assert b'"object_type": "TX_EQUITY_COMPENSATION_RELEASE"' in data
64+
6065
except (PermissionError, NotADirectoryError):
6166
# Bugs in windows give permission errors for absolutely no reason
6267
# when deleting temporary files. Ignore them.

0 commit comments

Comments
 (0)