New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-39434: Avoid defaultdict with lambda in pickled dataclasses #844
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #844 +/- ##
==========================================
+ Coverage 87.91% 87.93% +0.02%
==========================================
Files 268 268
Lines 35240 35256 +16
Branches 7396 7392 -4
==========================================
+ Hits 30980 31004 +24
+ Misses 3119 3112 -7
+ Partials 1141 1140 -1
☔ View full report in Codecov by Sentry. |
ec80013
to
a51514a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget why we can't use a single pydantic model for this and instead have to have a pydantic model and a dataclass. Is it for performance reasons? Presumably the pydantic model would pickle just fine.
Can you add a bit more detail about having to drop defaultdict in the commit message?
a51514a
to
c3c26c9
Compare
Pickle does not like lambdas or local/nested methods, using a `dataclass.field` with defaultdict and default_factory as a lambda breaks pickle. Instead of defining a module-level factory method I decided to use a plain dict and its `setdefault` method. Also had to add explicit pickle method to StoredFileInfo, being a frozen dataclass it does not work by default with pickle.
c3c26c9
to
719fcf9
Compare
I'm not sure what the exact reason was, but I see that pydantic and dataclass have different structure, maybe pydantic is more YAML/JSON-friedly than the in-memory dataclass?
I updated the commit message. |
Pickle does not like lambdas or local/nested methods, using a
dataclass.field
with defaultdict and default_factory as a lambda breaks pickle. Instead of defining
a module-level factory method I decided to use a plain dict and its
setdefault
method.Also had to add explicit pickle method to StoredFileInfo, being a frozen
dataclass it does not work by default with pickle.
Checklist
doc/changes