Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-15 Thread 'Jonathan Vanasco' via sqlalchemy
Going beyond what Simon did.. I typically make make a table like `user_transaction`, which has all of the relevant information for the transaction: * User ID * Timestamp * Remote IP Using the sqlalchemy hooks, I'll then do something like: * update the object table with the user_transaction id

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-15 Thread Jean-Philippe Laverdure
Ohhh, that sounds perfect ! And since I already make use of class based views, that should be dead simple to put in place. Thanks for the support, guys Cheers, JP On Mon, 15 Mar 2021 at 06:46, Simon King wrote: > I use pyramid as a web framework, and when I create the DB session for > each

Re: [sqlalchemy] Using Abstract Base Classes with ORM Table Classes

2021-03-15 Thread Mike Bayer
you no longer have to use DeclarativeMeta at all, you can use a class decorator: https://docs.sqlalchemy.org/en/14/orm/mapping_styles.html#declarative-mapping-using-a-decorator-no-declarative-base if you are on 1.3, there's a way to get the same effect in 1.3 using the instrument_declarative

Re: [sqlalchemy] Injecting User info into _history table to track who performed the change

2021-03-15 Thread Simon King
I use pyramid as a web framework, and when I create the DB session for each request, I add a reference to the current request object to the DB session. The session object has an "info" attribute which is intended for application-specific things like this:

Re: [sqlalchemy] Create Sqlalchemy ORM class from regular class gets "has no attribute ''_sa_instance_state''"

2021-03-15 Thread Simon King
I haven't followed your code in detail, but I think the problem might be here: clazz = school.Class('12', 'A') students = [ Student("Name1", "Sname1", clazz=clazz, code='aa7'), Student("Name2", "Sname2", clazz=clazz, code='bb7'), Student("Name3", "Sname3",

Re: [sqlalchemy] SQLAlchemy database record created on import of module

2021-03-15 Thread Simon King
I suggest you set up an event listener for the "after_attach" event on your session: https://docs.sqlalchemy.org/en/13/orm/events.html#sqlalchemy.orm.events.SessionEvents.after_attach Then you can set a breakpoint in the listener (or raise an exception, or use the traceback module to print a