apply ignore_nonexistent fix from declarative to straight mappers

Issue #2153 resolved
Mike Bayer repo owner created an issue

test:

from sqlalchemy import *
from sqlalchemy.orm import *

metadata = MetaData()

class Base(object): pass

base_table = Table("base", metadata,
    Column("id", Integer, primary_key=True),
    Column("target_type", String))

mapper(Base, base_table, polymorphic_on=base_table.c.target_type)


class Derived(Base): pass

derived_table = Table("derived", metadata,
    Column("id", Integer, ForeignKey("base.id"), primary_key=True),
    Column("owner_id", Integer, ForeignKey("owner.owner_id"), nullable=False))

mapper(Derived, derived_table, polymorphic_identity="derived", inherits=Base)


class Owner(object): pass

owner_table = Table("owner", metadata,
    Column("owner_id", Integer, primary_key=True))

mapper(Owner, owner_table)

patch:

diff -r 7eb29add0557371020a55fecc82d7d4c45575fcb lib/sqlalchemy/orm/mapper.py
--- a/lib/sqlalchemy/orm/mapper.py  Wed Apr 27 12:51:50 2011 -0400
+++ b/lib/sqlalchemy/orm/mapper.py  Thu Apr 28 16:26:57 2011 +0200
@@ -256,7 +256,8 @@
                         # want (allows test/inheritance.InheritTest4 to pass)
                         self.inherit_condition = sqlutil.join_condition(
                                                     self.inherits.local_table,
-                                                    self.local_table)
+                                                    self.local_table,
+                                                    ignore_nonexistent_tables=True)
                     self.mapped_table = sql.join(
                                                 self.inherits.mapped_table, 
                                                 self.local_table,

Comments (2)

  1. Mike Bayer reporter

    took two approaches here. in 0.7 4bc2402cc0bc585af1d0e7d59000f73cf20cf452 , changed the join_condition() function as well as the "no referenced" exceptions to coordinate information about the tablename/columnname being searched for so that it raises for relevant FKs every time, never raises for irrelevant FKs. in 0.6, did the simple patch, 739671e0c97f914c069de290fa24ed75d3cb376f (was originally in 0.7 via 7adcb1c7443265fc99d05714c964c795f0fe1c13). This has the slight chance of returning a less-than-descriptive error in the unusual case that two different MetaData objects are in use.

  2. Log in to comment