Skip to content

Fixes: #1877 - compare Identity and Computed defaults regardless of compare_server_default - #1885

Closed
anish-yen wants to merge 4 commits into
sqlalchemy:mainfrom
anish-yen:fix-identity-computed-compare-gate
Closed

anish-yen wants to merge 4 commits into
sqlalchemy:mainfrom
anish-yen:fix-identity-computed-compare-gate

Conversation

@anish-yen

Copy link
Copy Markdown

Fixes: #1877

As of 1.18.0, autogenerate no longer detects Identity changes on an existing column and no longer emits the "Computed default cannot be modified" warning unless compare_server_default is set. In 1.17.2 and earlier these ran regardless of that option, which only gated comparison of plain server defaults.

Cause

The 1.18 plugin restructure (e532a7e) made the first-priority comparator _user_compare_server_default stop the whole dispatch chain when the option is unset (False), so the computed and identity comparators registered behind it never ran.

Fix

When the option is False, _user_compare_server_default now stops the chain only for plain defaults. If either side is Computed or Identity it continues, letting _compare_computed_default and _compare_identity_default run as they did through the 1.17 series. Plain server default comparison stays gated, and a user callable's True/False/None semantics are unchanged.

Tests

New PGIdentityComputedNoCompareServerDefaultTest in tests/test_postgresql.py covers the four cases from the issue reproducer with compare_server_default=False (add, remove, and change Identity; change Computed warns), plus two controls: the Identity diff is still detected with the option enabled, and plain server default changes stay gated when it is disabled. The four regression cases fail on main without this change and pass with it; the controls pass both ways.

Ran: tests/test_postgresql.py and the server_default/identity/computed test selection against PostgreSQL 16, tests/test_autogen_diffs.py and the same selection against SQLite, plus black, zimports, flake8 and mypy per tox.ini.

This contribution was prepared with AI assistance (Instinct agent): the fix and tests were written with AI tooling and verified locally as described above.

…efault

Add handling for computed and identity server defaults in comparison.
…efault

Fix missing newline at end of file in server_defaults.py
…efault

Add tests for identity and computed column comparisons without gating by compare_server_default option.
…efault

Fixed regression in autogenerate detection for Identity and Computed column defaults.
@sqla-tester

Copy link
Copy Markdown
Collaborator

Hi, and thanks for the pull request!

This project accepts pull requests only for issues that a maintainer has already marked with the open for pull requests label. That way we can settle on an approach before anyone spends time writing code.

This pull request references issue #1877, which hasn't been marked open for pull requests, so the change isn't authorized yet and I'm closing it automatically. Once a maintainer adds the label to #1877, reopen this pull request and it will stay open. If #1877 needs more detail before that can happen, a complete runnable example is usually the missing piece, and adding one to the issue is the fastest way to get there.

This is automatic and procedural. It isn't a judgment on your change, and nothing you've written here is lost.

Thanks for your interest in the project!

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.

Identity and Computed comparison skipped when compare_server_default is not set, as of 1.18.0

2 participants