- changed status to resolved
eval_none logic isn't resolving col to prop
Issue #4031
resolved
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
column1 = Column('column1', JSON, nullable=False)
_column2 = Column('column2', JSON, nullable=False)
e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
Base.metadata.drop_all(e)
Base.metadata.create_all(e)
session = Session(e)
# Succeeds
session.add(A(column1=[], _column2=[]))
session.flush()
# Succeeds
session.add(A(column1=None, _column2=[]))
session.flush()
# Fails with integrity error
session.add(A(column1=[], _column2=None))
session.flush()
this would be the patch but need to confirm key is always present in _columntoproperty in this context:
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 1042442..68103d2 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -2020,7 +2020,7 @@ class Mapper(InspectionAttr):
(
table,
frozenset(
- col.key for col in columns
+ self._columntoproperty[col].key for col in columns
if col.type.should_evaluate_none
)
)
Comments (2)
-
reporter -
reporter Check for column object in eval_none, not propkey
Fixed bug involving JSON NULL evaluation logic added in 1.1 as part of
3514
where the logic would not accommodate ORM mapped attributes named differently from the :class:.Column
that was mapped.Change-Id: I1848afcfb63ad7f074f315d8d3097666069b42be Fixes:
#4031(cherry picked from commit e2ede596adff3ce584f8c43ba024cafabc509a06)→ <<cset db3c58f9ee93>>
- Log in to comment
Check for column object in eval_none, not propkey
Fixed bug involving JSON NULL evaluation logic added in 1.1 as part of
3514
where the logic would not accommodate ORM mapped attributes named differently from the :class:.Column
that was mapped.Change-Id: I1848afcfb63ad7f074f315d8d3097666069b42be Fixes:
#4031→ <<cset 7628ff39dcea>>