Skip to content
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-37214: Fix problem with JSON formatter when Pydantic is used but Dict requested #761

Merged
merged 6 commits into from Dec 9, 2022

Conversation

timj
Copy link
Member

@timj timj commented Dec 7, 2022

JSON natively reads dict and so was never triggering the conversion code to the proper internal type before converting that to a dict. For TaskMetadata this could lead to oddities because the dict view of TaskMetadata does not match the internal model layout.

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

TallJimbo and others added 2 commits December 7, 2022 16:20
Now that read storage class being different to write
storage class no longer directly means that a component
is being used, the logic in FileFormatter to extract
a component has to change.

1. The extraction must happen from the original python
   type that was written and not the, possibly, generic
   python type read from disk. This requires we do a
   coercion before extracting the component.
2. Built-in types must always be converted to the
   original storage class before conversion to the
   requested read storage class.
3. Remove duplicate logic from JSON and YAML that
   was trying to convert built-in types to the
   requested type. This now has moved to the
   parent class.
@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Base: 85.32% // Head: 85.37% // Increases project coverage by +0.05% 🎉

Coverage data is based on head (c2e3f5e) compared to base (9c43a39).
Patch coverage: 95.40% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #761      +/-   ##
==========================================
+ Coverage   85.32%   85.37%   +0.05%     
==========================================
  Files         260      261       +1     
  Lines       34560    34605      +45     
  Branches     5819     5816       -3     
==========================================
+ Hits        29488    29544      +56     
+ Misses       3826     3818       -8     
+ Partials     1246     1243       -3     
Impacted Files Coverage Δ
python/lsst/daf/butler/formatters/yaml.py 76.74% <66.66%> (+12.03%) ⬆️
python/lsst/daf/butler/formatters/file.py 80.28% <91.66%> (+4.41%) ⬆️
python/lsst/daf/butler/formatters/json.py 84.37% <100.00%> (+8.81%) ⬆️
...ython/lsst/daf/butler/tests/_examplePythonTypes.py 88.78% <100.00%> (+0.66%) ⬆️
...on/lsst/daf/butler/tests/dict_convertible_model.py 100.00% <100.00%> (ø)
tests/test_datastore.py 99.33% <100.00%> (+0.02%) ⬆️
...ython/lsst/daf/butler/core/storageClassDelegate.py 45.83% <0.00%> (-2.50%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@TallJimbo TallJimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Only comment is probably a case of idle musing about future possibilities.

python/lsst/daf/butler/formatters/file.py Outdated Show resolved Hide resolved
Remove the requirement that we only do this if we did not
write it originally as a built-in type -- it didn't really
affect the code because of the presence of the isinstance
check later on (which has now moved into the main check).
Test that we can round trip Pydantic models, dataclasses,
classes that get created from dicts, and tuples using JSON
and YAML formatters.
@timj timj merged commit ba46c3b into main Dec 9, 2022
@timj timj deleted the tickets/DM-37214 branch December 9, 2022 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants