Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Model.objects.all()yields instances whose path fields (e.g. the primary keyused in the datafile pattern) have the wrong type. For example:
This is tracked in #147 (the existing
test_values_are_filled_from_disktestwas marked
xfail).Root cause
Manager.all()extracts placeholder values from the filename viaparse(),which returns strings. Unlike the other attributes, these path fields are not
stored in the file contents, so they never pass through the field's converter
in
Mapper.load()—attrsdeliberately excludes pattern fields (seecreate_mapper()). The raw strings are then handed toManager.get(), whichsets them on the instance unchanged.
Change
Coerce the path-derived values to their declared types before calling
get(),reusing the existing
map_type()converter machinery (the same onecreate_mapper()uses for regular attributes):_coerce_values()builds a{field.name: field}lookup from the dataclass'sinitfields and runs each value throughmap_type(field.type).to_python_value().Fields without a matching declaration (or without
init) pass throughunchanged.
Verification
xfailmarker fromtest_values_are_filled_from_disk; it nowpasses.
pytest tests/: 128 passed, 1 skipped, 4 xfailed (no regressions; theremaining xfails are unrelated pre-existing issues).
mypy,black --check,isort --check,pylint, andpydocstyleall pass.