1.0.0b3: regression with single-table inheritance and constraint added in a subclass
Hi,
The attached example works fine with 0.9.7, but 1.0.0b3 gives the following error: sqlalchemy.exc.ArgumentError: Can't add unnamed column to column collection
Gabor
Comments (10)
-
repo owner -
repo owner In 0.9, CheckConstraint has the omission of even being able to track columns, so that's why this doesn't raise in 0.9.
-
reporter In the real code I use
__declare_last__()
to process__extra_table_args__
, but the error triggered even without that, so I omitted it to make the test case simpler. -
reporter So what's the solution? Do I have to start passing explicit names to Column() to be able to use CheckConstraint?
-
repo owner well the immediate works-right-now solution is:
class VlanInterface(Interface): parent_id = Column(ForeignKey(Interface.id, name='iface_parent_fk')) __mapper_args__ = {'polymorphic_identity': 'vlan'} CheckConstraint(or_( VlanInterface.parent_id != null(), Interface.interface_type != 'vlan'), name='iface_vlan_ck')
the very interesting way that your test case actually manages to do "auto-attach" is because one column is attached to the table already with its name, on the superclass, so it finds the table.
-
reporter Ok, that does not look bad, I'll try it. Thanks!
-
repo owner it will work in 0.9 and 1.0. I'm poking around still but your test is really a much thinner edge case than it initially seems (only CheckConstraint, only on single-table inheritance subclass w/ extra column. wont work any other way in 0.9)
-
repo owner I might "wontfix" this but let me look at it later as it isn't as urgent. I'm sure other people are going to hit similar issues.
-
repo owner - changed status to resolved
- The "auto-attach" feature of constraints such as :class:
.UniqueConstraint
and :class:.CheckConstraint
has been further enhanced such that when the constraint is associated with non-table-bound :class:.Column
objects, the constraint will set up event listeners with the columns themselves such that the constraint auto attaches at the same time the columns are associated with the table. This in particular helps in some edge cases in declarative but is also of general use. fixes#3341
→ <<cset bdcaa0f6ca58>>
-
repo owner we're going to have a lot of betas.... anyway you got it
- Log in to comment
this approach is a hack in the first place, as 0.9 doesn't support table_args on the inherited class and this relies upon CheckConstraint happening to do a certain kind of autoattach (e.g. UniqueConstraint doesn't do it).
that said, the autoattach feature in 1.0 is more aggressive but to work around unnamed columns might require a lot of rearrangement.