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

2021-03-12 Thread Elmer de Looff
Hi JP,

Depending on how you've implemented your history tracking, that routine is
quite far removed from your web framework and getting a neat, clean way of
dealing with that might not be within reach.

However, most web frameworks have some concept of a threadlocal request (or
function to retrieve it), which you could invoke and if such a request
exists, you could use that to load whatever user identity you have
available on there (again, the details differ, but this tends to be a
shared feature). From there you can store the user either as a foreign key,
or a unique identifier like email. Which one you pick would depend on how
you want the history to be affected when you delete a user record for
example.



On Fri, Mar 12, 2021 at 11:58 PM JPLaverdure  wrote:

> Hello everyone,
>
> We already have the ability to timestamp the creation of the history row,
> but it would also be interesting to be able to track the user responsible
> for the content update.
> I would like to get suggestions on the best way to achieve this.
>
> I realize this is somewhat outside the scope of sqlalchemy as the notion
> of a "logged in user" is more closely related to the context of the
> app/webapp using SQLAlchemy as its ORM but maybe other people would benefit
> from having a way to inject arbitrary data in the history table.
>
> Ideally, I would like the insert in the _history table to be atomic, so I
> feel like hooking an update statement to an event might not be the way to
> go.
> I'm tempted to modify the signature of before_flush but I'm not sure where
> it gets called.
>
> Any help is welcome !
> Thanks
>
> JP
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sqlalchemy/82a24998-14e1-4ff4-a725-dd25c20a8bf2n%40googlegroups.com
> 
> .
>


-- 

Elmer

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAA7D1eHrc7YYH2soeAAYRGea1twc2c%3Dx6yxuZ6D4rRmAFeTd1g%40mail.gmail.com.


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

2021-03-12 Thread JPLaverdure
Hello everyone,

We already have the ability to timestamp the creation of the history row, 
but it would also be interesting to be able to track the user responsible 
for the content update. 
I would like to get suggestions on the best way to achieve this.

I realize this is somewhat outside the scope of sqlalchemy as the notion of 
a "logged in user" is more closely related to the context of the app/webapp 
using SQLAlchemy as its ORM but maybe other people would benefit from 
having a way to inject arbitrary data in the history table.

Ideally, I would like the insert in the _history table to be atomic, so I 
feel like hooking an update statement to an event might not be the way to 
go.
I'm tempted to modify the signature of before_flush but I'm not sure where 
it gets called.

Any help is welcome !
Thanks

JP

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/82a24998-14e1-4ff4-a725-dd25c20a8bf2n%40googlegroups.com.


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

2021-03-12 Thread ScottBot
I have a game that I am coding for school (not a project or homework) and I 
am trying to use a SQLite database with sqlalchemy to store the game info. 
I don't know what the problem is or how I can fix it. Any help is 
appreciated. 
https://stackoverflow.com/questions/66591466/sqlalchemy-orm-from-regular-class

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/b3e6fb67-6cab-4484-8c39-a01999640e67n%40googlegroups.com.