Repository navigation
Conversation
|
Some concerns i have:
|
|
for those tests, we try to get the best of both worlds, that is, just one test method, but still keeping things separate, using either as far as the initializer, overall this feature still has me a bit nervous any suggestions @CaselIT ? |
|
Thank you, I made changes to the test methods to include My reasoning for implementing UniqueConstraint initializer was I wanted to make sure that attach_to_table was only available for UniqueConstraint. Now the actual syntax/implementation of the initializer I was hesitant so I just looked at other classes that inherited ColumnCollectionConstraint to see how they were implemented, I ended up following PrimaryKeyConstraint initializer. |
| deferrable: Optional[bool] = None, | ||
| initially: Optional[str] = None, | ||
| info: Optional[_InfoType] = None, | ||
| attach_to_table: bool = True, |
There was a problem hiding this comment.
attach_to_table=False is still ignored for CheckConstraint, ForeignKeyConstraint, and PrimaryKeyConstraint: it gets swallowed by **dialect_kw with an SAWarning and each constraint is still attached. #13048 explicitly asks for all constraints, but this only exposes the flag on UniqueConstraint.
There was a problem hiding this comment.
Thank you for the correction! I'll make the changes to allow all constraints to utilize the attach_to_table flag instead of just UniqueConstraint
f01ac20 to
a4375aa
Compare
Description
attach_to_table has been included for UniqueConstraint and Index to allow users to choose whether to include or withhold them from the Table (Table.constraints for UniqueConstraint, Table.indexes for Index). attach_to_table defaults to True for both UniqueConstraint and Index. So if set to True or not included UniqueConstraint / Index will be added to the Table.
For UniqueConstraint, setting attach_to_table to False prevents
parent.constraints.add(self)from executing inColumn._set_parent(). attach_to_table is checked viagetattrFor Index, setting attach_to_table to False prevents
table.indexes.add(self)from executing inIndex._set_parent()force_attach has been included in
Table.append_constraints(), and carried via**kw, to allow users to override attach_to_table. For situations where UniqueConstraint or Index was defined before the Table creation and attach_to_table is set to False, users can use that same UniqueConstraint or Index to append to table at a later time. For exampleunique_constraint = UniqueConstraint("x", attach_to_table=False)orindex = Index("x", attach_to_table=False), then Table is defined, thenTable.append_constraint(unique_constraint)orTable.append_constraint(index).For UniqueConstraint, regardless of attach_to_table, using
Table.append_constraint(constriant)allows for execution ofparent.constraints.add(self)inColumn._set_parent().For Index, regardless of attach_to_table, using
Table.append_constraint(index)allows for execution oftable.indexes.add(self)inIndex._set_parent().Fixes: #13048
Checklist
This pull request is:
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
Fixes: #<issue number>in the commit messageinclude a complete example of how the feature would look.
Fixes: #<issue number>in the commit messageHave a nice day!