Hi Mike,
When using `column_property`, this `select(User).from_statement(ins.returing(User))` construct will not load in the column property. Instead the ORM will issue a second query when the column property is accessed.
I am able to get it working using the following: `select(User).from_statement(ins.returing(*select(User).selected_columns))`
I get your point that there may not be much of a demand for this, but I would argue that it is a bit unexpected for `returning(User)` to return a Core row, and that the solution is bit unintuitive.
I think it should be as easy as .returning(User) and it should return the full ORM model with column_properties preloaded.
This proposed change is backwards incompatible right? E.g. if people are depending on `returning(User)` returning a core Row in 2.0, is it OK to change this to return a Model instance in 2.1?
By the way, I think I found a bug with insert().values() when
the ORM uses different field names than the Database column names. update().values() works fine, but not insert().values().
Please check my issue here when you have a moment.
------
Here is how to reproduce the case where column_property results in an extra query, if you are interested:
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
first_name = Column(String(30))
last_name = Column(String(30))
full_name = column_property(first_name + " " + last_name)
# returning(User) triggers extra query on column_property access
res = session.execute(select(User).from_statement(insert(User).values(first_name='foo', last_name='bar').returning(User)))
user = res.scalars().one()
# This triggers a select
print(user.full_name)
session.expunge(user)
# normal query does not trigger a select as expected
res = session.execute(select(User).where(User.id ==
user.id))
user = res.scalars().one()
print(user.full_name)
session.expunge(user)
# use *selected(User).selected_columns to avoid triggering an extra select
res = session.execute(select(User).from_statement(update(User).values(first_name='foo2').where(User.id ==
user.id).returning(*select(User).selected_columns)))
user = res.scalars().one()
# no extra query
print(user.full_name)
Thanks and best regards,
Matthew