Repository navigation
feat(attributes): add default_for_new attribute for model fields and update related documentation - #553
Open
marvelefe wants to merge 4 commits into
Open
feat(attributes): add default_for_new attribute for model fields and update related documentation#553marvelefe wants to merge 4 commits into
marvelefe wants to merge 4 commits into
Conversation
…update related documentation
Member
|
Thanks, Efe! The existing tests and examples passed. I found two cases we should fix before merging:
Could you adjust the default selection on save, keep the loading state specific to the object being loaded, and add Python regression tests for these cases? Thanks for working on this 🙂 |
|
Author
|
@leandrodamascena Fixed both now with regression tests, and the integration suite passes |
This branch has not been deployed
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.



Summary
Adds a
default_for_newattribute option. New models use it when the field is omitted. Stored items that lack the field still usedefault.Closes #487
Behavior
default_for_newwhen the field is omitted. Otherwisedefaultapplies, as before.from_dict,get,query,scan, batch and index reads) always usesdefault. Partial projections never get a creation default.False,0, andNone.default_for_new=Nonemeans no creation default, sorequiredstill applies.defaultbehave as before.Persistence
save(full_replace=True), and loaded items with no changes.Changes
attributes/base.py: new option andUNSETsentinel.attributes/{primitives,special,compressed,decimal,s3,vector}.py: constructors that takedefaultacceptdefault_for_new._internal/_model/_base.py: default selection in the constructor and auto-generate handling. AContextVarmarks the loading path infrom_dict.docs/guides/attributes.mdanddocs/examples/models/default_for_new.py: guide section and example.tests/unit/test_default_for_new.py: 22 new tests.Testing
uv run pytest tests/unit/): 1129 passed.ruff,ty): pass.uv run pytest tests/integration/): 867 passed, 8 skipped, 1 failed.test_distributed_lock.py::test_native_short_retry_recovery[0.05], which raisesLock request timed out. It fails when run alone, and the lock code does not import any module this PR changes. It's a pre-existing failureDOCKER_HOSTpointing at the Docker Desktop socket andTESTCONTAINERS_RYUK_DISABLED=true.