Skip to content

fix(sqlalchemy): skip system columns during persistence#848

Open
tysoncung wants to merge 1 commit intolitestar-org:mainfrom
tysoncung:fix/802-skip-system-columns
Open

fix(sqlalchemy): skip system columns during persistence#848
tysoncung wants to merge 1 commit intolitestar-org:mainfrom
tysoncung:fix/802-skip-system-columns

Conversation

@tysoncung
Copy link
Copy Markdown

Problem

Columns with system=True (e.g., PostgreSQL system columns) cause an OperationalError when using create_sync/create_async because the factory tries to persist values for these server-managed columns.

Solution

Handle system columns the same way computed columns are already handled:

  1. Detect column.system in get_type_from_column and annotate with a {"system": True} constraint
  2. Skip system-constrained fields in should_set_field_value when skip_system_fields is set
  3. Set skip_system_fields=True during create_sync/create_async (same as skip_computed_fields)

Values are still generated normally during build() — only persistence operations skip these fields.

Files Changed

  • polyfactory/factories/sqlalchemy_factory.py:
    • Added system to SQLAlchemyConstraints
    • Added skip_system_fields to SQLAlchemyBuildContext
    • Detect system=True columns in get_type_from_column
    • Skip system fields in should_set_field_value during persistence

Closes #802

…#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
@tysoncung tysoncung requested a review from adhtruong as a code owner March 28, 2026 15:01
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.

Bug: using columns with system=True causes OperationalError exception

1 participant