get eager_defaults to use RETURNING for ad-hoc SQL, not just column defaults

Issue #3401 new
Mike Bayer repo owner created an issue

this might take some rearrangement of persistence logic to work out, but this should work:

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)
    value = Column(Integer) #, server_default=FetchedValue())

    __mapper_args__ = {'eager_defaults': True}

e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)
Base.metadata.create_all(e)

s = Session(e)
a1 = A(value=literal_column("1 + 1"))
s.add(a1)
s.flush()

# does a fetch, unless the server_default above is set.
print a1.value

also eager_defaults should have a section in the mapper docs describing it beyond just the docstring, now that returning makes it useful.

Comments (2)

  1. Log in to comment