- attached schema.py.diff
A failed table autoload hampers subsequent definition of the same table
When an autoload of a non-existing table fails:
>>> from sqlalchemy import *
>>> md = BoundMetaData('sqlite:///test.db')
>>> Table('nonesuch', md, autoload=True)
Traceback (most recent call last):
...
sqlalchemy.exceptions.NoSuchTableError: nonesuch
the table remains in the metadata dict:
>>> md.tables
{'nonesuch': Table('nonesuch',
BoundMetaData(),
schema=None)}
that way, a subsequent definition of the same table fails:
>>> Table('nonesuch', md,
... Column('id', Integer, primary_key=True))
Traceback (most recent call last):
...
sqlalchemy.exceptions.ArgumentError: Table 'None.nonesuch' is already
defined. specify 'redefine=True' to remap columns, or 'useexisting=True'
to use the existing table
One could use the 'redefine=True' parameter to avoid this error, but I would prefer avoiding it, because in some cases that would actually, and wrongly, redefine a table.
The attached patch deregisters the table, but only when autoloading raises NoSuchTableError, and therefore makes the subsequent definition work.
Comments (4)
-
Account Deleted -
repo owner - changed status to resolved
one issue with this is that MySQL is not able to raise NoSuchTableError at the moment; while all the other DB's reflection method uses a "if no rows, then no table" approach, MySQL's "describe" throws an exception. ill make a separate ticket for that.
anyway this is patched in changeset:1829
-
repo owner - changed milestone to 0.4.0
Milestone next micropoint release deleted
-
repo owner - removed milestone
Removing milestone: 0.4.0 (automated comment)
- Log in to comment
Fix for the problem described in the text