[Sqlalchemy-tickets] Issue #3794: Setting column as None does not explicitly add the NULL to insert
Brought to you by:
zzzeek
From: Konsta V. <iss...@bi...> - 2016-09-14 06:00:21
|
New issue 3794: Setting column as None does not explicitly add the NULL to insert statement https://bitbucket.org/zzzeek/sqlalchemy/issues/3794/setting-column-as-none-does-not-explicitly Konsta Vesterinen: The following code illustrates this problem: ``` #!python import sqlalchemy as sa from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base engine = sa.create_engine( 'postgres://postgres@localhost/test' ) engine.echo = True Base = declarative_base() Session = sessionmaker(bind=engine) session = Session() class Question(Base): __tablename__ = 'question' id = sa.Column(sa.Integer, primary_key=True) weight = sa.Column(sa.Integer, default=1) Base.metadata.create_all(bind=session.bind) q = Question(weight=None) session.add(q) session.commit() assert q.weight is None ``` The problem also exists by changing the ``default=1`` to ``server_default='1'``. Also in this case the explicit weight=NULL is not added to INSERT statement. |