Skip to content

compare identity, computed defaults when compare_server_default is false - #1882

Closed
Fire162 wants to merge 1 commit into
sqlalchemy:mainfrom
Fire162:fix-1877-identity-computed-compare
Closed

Fire162 wants to merge 1 commit into
sqlalchemy:mainfrom
Fire162:fix-1877-identity-computed-compare

Conversation

@Fire162

@Fire162 Fire162 commented Oct 17, 2026

Copy link
Copy Markdown

Fixes #1877

Problem

In 1.18.0, column comparators were moved to PriorityDispatcher. _user_compare_server_default was registered at DispatchPriority.FIRST under the "server_default" subgroup. When compare_server_default=False (the default setting in Alembic migration contexts), _user_compare_server_default returns PriorityDispatchResult.STOP. This aborts all subsequent comparators registered in the "server_default" subgroup before _compare_computed_default or _compare_identity_default can run.

Additionally, _setup_autoincrement was registered under the "server_default" subgroup, causing autoincrement metadata on altered columns to be dropped whenever server default comparison was stopped.

Solution

  1. Register _compare_computed_default and _compare_identity_default at DispatchPriority.FIRST in the "server_default" subgroup so they execute before _user_compare_server_default (registered at DispatchPriority.MEDIUM).
  2. Set alter_column_op.existing_server_default = conn_col_default in both _compare_computed_default and _compare_identity_default.
  3. Return PriorityDispatchResult.STOP in _compare_identity_default whenever an identity default is present, preventing fallback into plain server default comparison.
  4. Register _setup_autoincrement under the "autoincrement" element so it runs independently of server default comparison.
  5. Add unit tests in CompareServerDefaultTest verifying that computed warnings, identity modifications, and autoincrement metadata flags are preserved when compare_server_default=False.

In 1.18.0, comparators were refactored to use PriorityDispatcher.
_user_compare_server_default was registered at DispatchPriority.FIRST
under the "server_default" subgroup. When compare_server_default is
omitted or False (the default), _user_compare_server_default returns STOP,
which aborted all subsequent comparators registered in the "server_default"
subgroup before _compare_computed_default and _compare_identity_default
could run.

In addition, _setup_autoincrement was erroneously registered under the
"server_default" subgroup, causing autoincrement settings to be skipped
when server default comparison stopped.

Fix this by:
1. Registering _compare_computed_default and _compare_identity_default at
   DispatchPriority.FIRST in the "server_default" subgroup, so they run
   before _user_compare_server_default (at DispatchPriority.MEDIUM).
2. Ensuring _compare_identity_default always returns STOP when an identity
   default is present, and populates existing_server_default.
3. Setting existing_server_default in _compare_computed_default.
4. Registering _setup_autoincrement under the "autoincrement" element.

Fixes: sqlalchemy#1877
@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