eval_none logic isn't resolving col to prop

Issue #4031 resolved
Michael Bayer
repo owner created an issue
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)

session = Session(e)

# Succeeds
session.add(A(column1=[], _column2=[]))

# Succeeds
session.add(A(column1=None, _column2=[]))

# Fails with integrity error
session.add(A(column1=[], _column2=None))

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):
-                    col.key for col in columns
+                    self._columntoproperty[col].key for col in columns
                     if col.type.should_evaluate_none

Comments (2)

  1. Michael Bayer 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

    → <<cset 7628ff39dcea>>

  2. Log in to comment