Having in mind documentation remarks on is_modified for scalar values is
modified = session.is_modified(obj) and obj in session.dirty
a good way to determine if obj was modified?
W dniu środa, 4 listopada 2015 02:03:05 UTC+1 użytkownik Michael Bayer
napisał:
>
>
>
> On 11/03/2015 03:21 PM,
In SQLAlchemy documentation there is an example of handling session with
context manager:
from contextlib import contextmanager
@contextmanagerdef session_scope():
"""Provide a transactional scope around a series of operations."""
session = Session()
try:
yield session
Mike,
Thank you for for the tip on _sessions, I think it is worth publishing
since it can make debugging easier. Regarding documentation it will be good
to mention session close() is not like file close() and closed session is
just ready for another transaction. Context manager is typically
Is there a stock function to test if an object attribute is a relationship?
I have created below function to test it, is there a better solution?
def is_relationship(obj, attr):
try:
p = inspect(getattr(type(obj), attr)).property
except (AttributeError, NoInspectionAvailable):
Works like a charm and looks much better.
> how about, "attr in inspect(obj).mapper.relationships" ?
>
> >
> >
> > --
> > SQLAlchemy -
> > The Python SQL Toolkit and Object Relational Mapper
> >
> > http://www.sqlalchemy.org/
> >
> > To post example code, please provide an MCVE: