adding None to collection fails ungracefully
Issue #2205
resolved
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Parent(Base):
__tablename__ = 'p'
id = Column(Integer, primary_key=True)
class Child(Base):
__tablename__ = 'c'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('p.id'))
parent = relationship(Parent, backref="children")
e = create_engine('sqlite://')
Base.metadata.create_all(e)
s = Session(e)
s.add(Parent(children=[None](None)))
Traceback (most recent call last):
File "test.py", line 25, in <module>
s.add(Parent(children=[None](None)))
File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/session.py", line 1144, in add
self._save_or_update_state(state)
File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/session.py", line 1159, in _save_or_update_state
halt_on=self._contains_state):
File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/mapper.py", line 1688, in cascade_iterator
parent_dict, visited_states, halt_on))
File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/properties.py", line 808, in cascade_iterator
get_all_pending(state, dict_)
File "/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/attributes.py", line 725, in get_all_pending
current_states = [c) for c in current]((instance_state(c),)
AttributeError: 'NoneType' object has no attribute '_sa_instance_state'
Comments (5)
-
reporter -
reporter - changed milestone to 0.7.2
this skips the None silently in 0.6 so let's just keep this on 0.7.
-
reporter #2229proposes adding a warning in 0.8. -
reporter - changed status to resolved
-
reporter - removed milestone
Removing milestone: 0.7.2 (automated comment)
- Log in to comment