DeclarativeReflection example doesn't accept overrides

Issue #2402 resolved
Former user created an issue

I tried to use the declarative feflection example against a view; but that wouldn't work as the ORM needs a primary key. Trying to override didn't work; the fix is simple: pass in *[ _ for _ in table.c ] to the Table constructor during DeclarativeReflectedBase.prepare().

I've added the DeclarativeReflectedBase class to the ext.declarative module and added a test to confirm the override isn't overriding. Then I've confirmed the fix clears the error below. I've made a pull-request of these changes.

I'd like guidance at this point: should I keep making DeclarativeReflectedBase a real part of the library, with real docs and tests? Or should I just patch the examples and be done with it?

ERROR: test.ext.test_declarative.ReflectionTest.test_override_declarative_reflection
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/lbruno/sqlalchemy/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/lbruno/sqlalchemy/./test/ext/test_declarative.py", line 3585, in test_override_declarative_reflection
    Base.prepare(self.engine)
  File "/home/lbruno/sqlalchemy/./lib/sqlalchemy/ext/declarative.py", line 1683, in prepare
    klass.__mapper__ = mapper(*args, **kw)
  File "/home/lbruno/sqlalchemy/./lib/sqlalchemy/orm/__init__.py", line 1116, in mapper
    return Mapper(class_, local_table, *args, **params)
  File "/home/lbruno/sqlalchemy/./lib/sqlalchemy/orm/mapper.py", line 203, in __init__
    self._configure_pks()
  File "/home/lbruno/sqlalchemy/./lib/sqlalchemy/orm/mapper.py", line 766, in _configure_pks
    (self, self.mapped_table.description))
ArgumentError: Mapper Mapper|Override|sqla_test__no_pkey could not assemble any primary key columns for mapped table 'sqla_test__no_pkey'

Comments (4)

  1. Mike Bayer repo owner

    the bug is in the new autoload_replace functionality. A patch is attached. Do you want to work it into your pull request ?

  2. Log in to comment