Hi, I love Schematics and I love SQLAlchemy, so I decided to try schemalchemy vs having two entity classes. Works great for single table.
I'm running into an issue with a one-to-many relationship though. If the record doesn't exist in both tables, it works fine. If there's an existing record, it seems to fail. I was wondering if you had experienced this in the past or may have any insight into how to fix the issue.
Here's my entity classes-
class ChildRecord(Base):
#SQLAlchemy Table Definition
__tablename__ = ‘child’
_child_id = Column(‘child_id', Integer, primary_key=True)
_parent_id = Column(‘parent_id', String, ForeignKey(‘parent.id'))
_type = Column('type', String)
_value = Column('value', String)
#Schematics Definition
type = StringType()
value = StringType()
#The Values don’t seem to be set properly for children
def fixValues(self):
self._type = self.type
self._value = self.value
End Fix
class ParentRecord(Base):
#SQLAlchemy Table Definition
__tablename__ = ‘parent’
_id = Column('id', String, primary_key=True, nullable=False)
_child = relationship(“ChildRecord”, collection_class=list,
cascade="all, delete-orphan", passive_deletes=True)
#Schematics Definition
child = ListType(ModelType(ChildRecord))
Here's the stack trace (database_shared.py is my code, doing a merge operation on the parent entity class, id like to do setter injection somehow and have the operations on the entity class itself... not sure if that's possible)
File "./database_shared.py", line 41, in MergeDBRow
self.session.merge(databaseObject)
File "./lib/sqlalchemy/orm/session.py", line 1709, in merge
load=load, _recursive=_recursive)
File "./lib/sqlalchemy/orm/session.py", line 1752, in merge
merged = self.query(mapper.class).get(key[1])
File "./lib/sqlalchemy/orm/query.py", line 831, in get
return self._get_impl(ident, loading.load_on_ident)
File "./lib/sqlalchemy/orm/query.py", line 864, in _get_impl
return fallback_fn(self, key)
File "./lib/sqlalchemy/orm/loading.py", line 219, in load_on_ident
return q.one()
File "./lib/sqlalchemy/orm/query.py", line 2718, in one
ret = list(self)
File "./lib/sqlalchemy/orm/loading.py", line 86, in instances
util.raise_from_cause(err)
File "./lib/sqlalchemy/util/compat.py", line 202, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "./lib/sqlalchemy/orm/loading.py", line 71, in instances
rows = [proc(row) for row in fetch]
File "./lib/sqlalchemy/orm/loading.py", line 432, in _instance
state.manager.dispatch.load(state, context)
File "./lib/sqlalchemy/event/attr.py", line 256, in call
fn(_args, *_kw)
File "./lib/sqlalchemy/orm/mapper.py", line 2860, in _event_on_load
instrumenting_mapper._reconstructor(state.obj())
File "./schemalchemy.py", line 94, in _reconstructor
self._set_mapped_field_values()
File "./schemalchemy.py", line 108, in _set_mapped_field_values
setattr(self, field_name, value)
File "", line 1, in set
File "./schemalchemy.py", line 46, in set
setattr(instance, self.column_name, getattr(instance, self.name))
File "./lib/sqlalchemy/orm/attributes.py", line 224, in set
instance_dict(instance), value, None)
File "./lib/sqlalchemy/orm/attributes.py", line 1027, in set
lambda adapter, i: adapter.adapt_like_to_iterable(i))
File "./lib/sqlalchemy/orm/attributes.py", line 1043, in _set_iterable
new_values = list(adapter(new_collection, iterable))
File "./lib/sqlalchemy/orm/attributes.py", line 1027, in
lambda adapter, i: adapter.adapt_like_to_iterable(i))
File "./lib/sqlalchemy/orm/collections.py", line 637, in adapt_like_to_iterable
given, wanted))
TypeError: Incompatible collection type: None is not list-like
Any help would be greatly appreciated! Thanks for contributing this library. ;)
Hi, I love Schematics and I love SQLAlchemy, so I decided to try schemalchemy vs having two entity classes. Works great for single table.
I'm running into an issue with a one-to-many relationship though. If the record doesn't exist in both tables, it works fine. If there's an existing record, it seems to fail. I was wondering if you had experienced this in the past or may have any insight into how to fix the issue.
Here's my entity classes-
Here's the stack trace (database_shared.py is my code, doing a merge operation on the parent entity class, id like to do setter injection somehow and have the operations on the entity class itself... not sure if that's possible)
Any help would be greatly appreciated! Thanks for contributing this library. ;)