so the quick and dirty approach is a flag I'm not enthused about,
nevertheless I don't plan on removing, called
_enable_transaction_accounting, that when set to False, will put the
Session in total SQLAlchemy 0.4 mode where there is no tracking or
expiry of state across transactions of any kind. This flag is in the
docs for Session, it goes alongside the autocommit etc. flags.
The more architectural answer is that the ORM considers these objects to
be proxies for state within a database transaction. That your GUI lives
outside of the span of a single transaction is correct, but also implies
that the pattern to persist the GUI to the database would involve
copying its state into the database structure, which in this case is
your ORM model. That is, the state of your GUI would in fact be
represented outside of those ORM objects.
You can do this kind of pattern by having the ORM objects represent the
GUI state as "detached" objects, then copy the state of those objects
into the session using a method like Session.merge. On an empty
Session this would incur a lot of SELECT statements, but you can try
working with session.merge(..., load=False) and feed the objects in, if
they have pending changes on them themselves you can use
sqlalchemy.orm.session.make_transient_to_detached() on each to set them
as "clean".
The best way would be that the GUI has its own dedicated data structure
that is distinct from your ORM model. A more high-end way of
representing this is to create "action" objects which represent things
the user does, like pressing a button or selecting a choice in a
dropdown. You log these "action" objects into a list as the user does
them, and when ready for persist, you "play" these objects into an ORM
model. This in formal parlance is known as the "command" pattern and
one reason it's key for GUIs is that it gives you "undo" ability for
free - each Command object can not only "play" itself into the GUI, it
can also "unplay" itself. Overall, the idea is not to look at the GUI
as a current set of state, look at it as the graphical representation of
a series of events that have occurred.
So you have "quick", "better", and "formalized" options on this.
>
> All the best,
>
> Philip
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
>
http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See
http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google
> Groups "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
sqlalchemy+...@googlegroups.com
> <mailto:
sqlalchemy+...@googlegroups.com>.
> To post to this group, send email to
sqlal...@googlegroups.com
> <mailto:
sqlal...@googlegroups.com>.
> Visit this group at
https://groups.google.com/group/sqlalchemy.
> For more options, visit
https://groups.google.com/d/optout.