feat: skip SQLAlchemy model fields with default values#845
Open
AlexPetul wants to merge 2 commits intolitestar-org:mainfrom
Open
feat: skip SQLAlchemy model fields with default values#845AlexPetul wants to merge 2 commits intolitestar-org:mainfrom
AlexPetul wants to merge 2 commits intolitestar-org:mainfrom
Conversation
2e16752 to
1df2588
Compare
1df2588 to
99be865
Compare
adhtruong
reviewed
Mar 26, 2026
Collaborator
adhtruong
left a comment
There was a problem hiding this comment.
Currently, the pattern used in other factories is to just detect that there is a default and omit supplying a value when this setting is on.
Does logic work if persistence is used? This may not be less complex though don't feel strongly on this given does feel clunkier to use
d344902 to
ebabc9c
Compare
Co-authored-by: Andrew Truong <40660973+adhtruong@users.noreply.github.com>
6408a43 to
b1e1221
Compare
Contributor
Author
Indeed, dataclasses, msgspec, etc. handle defaults at the runtime level, so omitting a value applies the default. But with alchemy it's different. Behavior with persistence remains unchanged:
|
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.
Description
Skip random value generation for SQLAlchemy fields that have a default value.
Although this works for most common cases, it has limitations for more advanced usage.
For example, context-sensitive default functions cannot be reliably evaluated:
Such defaults require an execution context, and there is no obvious or safe way to construct a
DefaultExecutionContext.Similarly, SQL expressions used as defaults (for example text("select ...")) cannot be evaluated without a db round-trip, so they cannot be resolved at factory/build time.
This implementation only supports simple scalar defaults and callable defaults without context parameters.
Closes #837