a fixed name to be assigned to the alias object.
[ticket:2030]
+ - A warning is emitted when a joined-table inheriting mapper
+ has no primary keys on the locally mapped table
+ (but has pks on the superclass table). [ticket:2019]
+
- sql
- Column.copy(), as used in table.tometadata(), copies the
'doc' attribute. [ticket:2028]
from itertools import chain, groupby
deque = __import__('collections').deque
-from sqlalchemy import sql, util, log, exc as sa_exc, event
+from sqlalchemy import sql, util, log, exc as sa_exc, event, schema
from sqlalchemy.sql import expression, visitors, operators, util as sqlutil
from sqlalchemy.orm import instrumentation, attributes, sync, \
exc as orm_exc, unitofwork, events
"Mapper %s could not assemble any primary "
"key columns for mapped table '%s'" %
(self, self.mapped_table.description))
+ elif self.local_table not in self._pks_by_table and \
+ isinstance(self.local_table, schema.Table):
+ util.warn("Could not assemble any primary "
+ "keys for locally mapped table '%s' - "
+ "no rows will be persisted in this Table."
+ % self.local_table.description)
if self.inherits and \
not self.concrete and \
),
)
+class NoPKOnSubTableWarningTest(testing.TestBase):
+
+ def _fixture(self):
+ metadata = MetaData()
+ parent = Table('parent', metadata,
+ Column('id', Integer, primary_key=True)
+ )
+ child = Table('child', metadata,
+ Column('id', Integer, ForeignKey('parent.id'))
+ )
+ return parent, child
+
+ def tearDown(self):
+ clear_mappers()
+
+ def test_warning_on_sub(self):
+ parent, child = self._fixture()
+
+ class P(object):
+ pass
+ class C(P):
+ pass
+
+ mapper(P, parent)
+ assert_raises_message(
+ sa_exc.SAWarning,
+ "Could not assemble any primary keys for locally mapped "
+ "table 'child' - no rows will be persisted in this Table.",
+ mapper, C, child, inherits=P
+ )
+
+ def test_no_warning_with_explicit(self):
+ parent, child = self._fixture()
+
+ class P(object):
+ pass
+ class C(P):
+ pass
+
+ mapper(P, parent)
+ mc = mapper(C, child, inherits=P, primary_key=[parent.c.id])
+ eq_(mc.primary_key, (parent.c.id,))
+
class PKDiscriminatorTest(_base.MappedTest):
@classmethod
def define_tables(cls, metadata):