Using the default_engine, instead of defining an engine causes a 'No connection established' error when defining a relation in a mapper
Issue #146
resolved
(original reporter: creiht) I have the following code block:
tiles = Table('tiles',
Column('id', Integer, primary_key = True),
Column('width', Integer),
Column('height', Integer),
Column('image', Binary),
)
tags = Table('tags',
Column('id', Integer, primary_key = True),
Column('name', String(50)),
Column('description', String),
)
tiles_tags = Table('tiles_tags',
Column('id', Integer, primary_key = True),
Column('tiles_id', Integer, ForeignKey('tiles.id')),
Column('tags_id', Integer, ForeignKey('tags.id')),
)
class Tile(object):
pass
class Tag(object):
pass
assign_mapper(Tag, tags)
assign_mapper(Tile, tiles, properties = {
'tags' : relation(Tag.mapper, tiles_tags, lazy=False,
backref=backref('tiles', lazy=False, private=True)
)
}
)
I get the following traceback:
exceptions.AttributeError Traceback (most recent call last)
/workspace/personal/sprite/<console>
/workspace/personal/sprite/spriteDB.py
41 assign_mapper(Tile, tiles, properties = {
42 'tags' : relation(Tag.mapper, tiles_tags, lazy=False,
---> 43 backref=backref('tiles', lazy=False, private=True)
44 )
45 }
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/__init__.py in assign_mapper(class_, *args, **params)
103 setattr(self, key, value)
104 class_.__init__ = __init__
--> 105 m = mapper(class_, *args, **params)
106 class_.mapper = m
107 class_.get = m.get
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/__init__.py in mapper(class_, table, *args, **params)
53 return class_mapper(class_)
54
---> 55 return Mapper(class_, table, *args, **params)
56
57 def clear_mappers():
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/mapper.py in __init__(self, class_, table, primarytable, properties, primary_key, is_primary, inherits, inherit_condition, extension, order_by, allow_column_override, entity_name, always_refresh, version_id_col, **kwargs)
223 for key, prop in l:
224 if getattr(prop, 'key', None) is None:
--> 225 prop.init(key, self)
226
227 # this prints a summary of the object attributes and how they
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/mapper.py in init(self, key, parent)
960 self.key = key
961 self.parent = parent
--> 962 self.do_init(key, parent)
963 def do_init(self, key, parent):
964 """template method for subclasses"""
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/properties.py in do_init(self, key, parent)
212
213 if self.backref is not None:
--> 214 self.backref.compile(self)
215 elif not objectstore.global_attributes.is_class_managed(parent.class_, key):
216 raise ArgumentError("Non-primary property created for attribute '%s' on class '%s', but that attribute is not managed! Insure that the primary mapper for this class defines this property" % (key, parent.class_.__name__))
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/properties.py in compile(self, prop)
884 cls = EagerLoader
885 relation = cls(prop.parent, prop.secondary, pj, sj, backref=prop.key, is_backref=True, **self.kwargs)
--> 886 prop.mapper.add_property(self.key, relation);
887 else:
888 # else set one of us as the "backreference"
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/mapper.py in add_property(self, key, prop)
247 proplist = self.columntoproperty.setdefault(col.original, [ 248 proplist.append(prop)
--> 249 prop.init(key, self)
250
251 def __str__(self):
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/mapper.py in init(self, key, parent)
960 self.key = key
961 self.parent = parent
--> 962 self.do_init(key, parent)
963 def do_init(self, key, parent):
964 """template method for subclasses"""
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/properties.py in do_init(self, key, parent)
216 raise ArgumentError("Non-primary property created for attribute '%s' on class '%s', but that attribute is not managed! Insure that the primary mapper for this class defines this property" % (key, parent.class_.__name__)) 217
--> 218 self.do_init_subclass(key, parent)
219
220 def _set_class_attribute(self, class_, key):
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/mapping/properties.py in do_init_subclass(self, key, parent, recursion_stack)
672 parent._has_eager = True
673
--> 674 self.eagertarget = self.target.alias()
675 # print "ALIAS", str(self.eagertarget.select()) #selectable.__class__.__name__
676 if self.secondary:
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/sql.py in alias(self, name)
1150 return Join(self, right, isouter = True, *args, **kwargs)
1151 def alias(self, name=None):
-> 1152 return Alias(self, name)
1153 def select(self, whereclause = None, **params):
1154 return select([self](])
), whereclause, **params)
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/sql.py in __init__(self, selectable, alias)
991 alias = n + "_" + hex(random.randint(0, 65535))[2:](2:)
992 self.name = alias
--> 993 if self.selectable.oid_column is not None:
994 self.oid_column = self.selectable.oid_column._make_proxy(self)
995 else:
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/sql.py in _oid_col(self)
1100 # OID remains a little hackish so far
1101 if not hasattr(self, '_oid_column'):
-> 1102 if self.engine.oid_column_name() is not None:
1103 self._oid_column = schema.Column(self.engine.oid_column_name(), sqltypes.Integer, hidden=True)
1104 self._oid_column._set_parent(self)
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/ext/proxy.py in oid_column_name(self)
32 # oid_column should not be requested before the engine is connected.
33 # it should ideally only be called at query compilation time.
---> 34 e= self.get_engine()
35 if e is None:
36 return None
/opt/local/lib/python2.4/site-packages/SQLAlchemy-0.1.5-py2.4.egg/sqlalchemy/ext/proxy.py in get_engine(self)
110 def get_engine(self):
111 if self.storage.engine is None:
--> 112 raise AttributeError('No connection established')
113 return self.storage.engine
114
AttributeError: No connection established
If I comment out the relation piece of the mapper, the code imports fine
If I define an engine, and pass it to the table functions, the code works fine
Comments (2)
-
Account Deleted -
repo owner - changed status to resolved
its just more OID column stuff, put a fix in changeset:1257. Also
#147is a new ticket calling for further refinement of the OID concept. - Log in to comment
(original author: creiht) Update:
I just tried defining a proxy engine instead and get the same error