fix(sqlalchemy): skip system columns during persistence#848
Open
tysoncung wants to merge 1 commit intolitestar-org:mainfrom
Open
fix(sqlalchemy): skip system columns during persistence#848tysoncung wants to merge 1 commit intolitestar-org:mainfrom
tysoncung wants to merge 1 commit intolitestar-org:mainfrom
Conversation
…#802) Columns with system=True (e.g., PostgreSQL system columns) should be skipped during persistence, similar to how computed columns are handled. Values can still be generated normally during build(), but are excluded when using create_sync/create_async. Changes: - Added 'system' to SQLAlchemyConstraints TypedDict - Added 'skip_system_fields' to SQLAlchemyBuildContext - Detect system=True on columns in get_type_from_column - Skip system fields in should_set_field_value during persistence - Set skip_system_fields=True in create_sync/create_async Closes litestar-org#802
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
Columns with
system=True(e.g., PostgreSQL system columns) cause anOperationalErrorwhen usingcreate_sync/create_asyncbecause the factory tries to persist values for these server-managed columns.Solution
Handle system columns the same way computed columns are already handled:
column.systeminget_type_from_columnand annotate with a{"system": True}constraintshould_set_field_valuewhenskip_system_fieldsis setskip_system_fields=Trueduringcreate_sync/create_async(same asskip_computed_fields)Values are still generated normally during
build()— only persistence operations skip these fields.Files Changed
polyfactory/factories/sqlalchemy_factory.py:systemtoSQLAlchemyConstraintsskip_system_fieldstoSQLAlchemyBuildContextsystem=Truecolumns inget_type_from_columnshould_set_field_valueduring persistenceCloses #802