Re: [sqlalchemy] compare a object/instance against its data in the database

2017-06-13 Thread Jacek Blocki
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,

[sqlalchemy] Session and context manager

2018-01-31 Thread Jacek Blocki
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

Re: [sqlalchemy] Session and context manager

2018-02-05 Thread Jacek Blocki
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

[sqlalchemy] How to test if an object attribute is a relationship

2018-09-06 Thread Jacek Blocki
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):

Re: [sqlalchemy] How to test if an object attribute is a relationship

2018-09-07 Thread Jacek Blocki
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: