[sqlalchemy] Re: Zope.sqalchemy: AttributeError: '_thread._local' object has no attribute 'value'

2020-10-24 Thread Jonathan Vanasco
The extract code you posted is incorrect.

You were given a step towards the right answer - you MUST invoke `register`.

I say a step, because there may be other factors going on.

However as you can see from the source code 
(https://github.com/zopefoundation/zope.sqlalchemy/blob/master/src/zope/sqlalchemy/datamanager.py#L293-L329),
 
the call to `register` is required because it invokes the 
ZopeTransactionExtenstion AND sets up the transaction events.

On Saturday, October 24, 2020 at 10:47:27 AM UTC-4 dever...@gmail.com wrote:

> I'm updating a working Pyramid app that uses sqlalchemy and have some 
> success by replacing ZopeTransactionExtension with ZopeTransactionEvents.
>
> On running initialise with my local .ini file, All goes well, the database 
> tables (MariaDB) are all written, but these errors occur:
>
> Traceback (most recent call last): "[...]sqlalchemy/util/_collections.py", 
> line 1055, in __call__ return self.registry.value AttributeError: 
> '_thread._local' object has no attribute 'value' During handling of the 
> above exception, another exception occurred: 
>
> [cruft omitted]
> "[...]sqlalchemy/orm/deprecated_interfaces.py", line 367, in 
> _adapt_listener ls_meth = getattr(listener, meth) AttributeError: 
> 'ZopeTransactionEvents' object has no attribute 'after_commit'
>
> For more code details, I've posted extracts from the models and main app 
> code on StackOverflow , but 
> with no joy so far.
>

-- 
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/1de6b5a3-4ca0-489a-abf6-4f4c582d6cc9n%40googlegroups.com.


[sqlalchemy] Zope.sqalchemy: AttributeError: '_thread._local' object has no attribute 'value'

2020-10-24 Thread Dave Everitt
I'm updating a working Pyramid app that uses sqlalchemy and have some 
success by replacing ZopeTransactionExtension with ZopeTransactionEvents.

On running initialise with my local .ini file, All goes well, the database 
tables (MariaDB) are all written, but these errors occur:

Traceback (most recent call last): "[...]sqlalchemy/util/_collections.py", 
line 1055, in __call__ return self.registry.value AttributeError: 
'_thread._local' object has no attribute 'value' During handling of the 
above exception, another exception occurred: 

[cruft omitted]
"[...]sqlalchemy/orm/deprecated_interfaces.py", line 367, in 
_adapt_listener ls_meth = getattr(listener, meth) AttributeError: 
'ZopeTransactionEvents' object has no attribute 'after_commit'

For more code details, I've posted extracts from the models and main app 
code on StackOverflow , but 
with no joy so far.

-- 
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/215fd25a-511c-492d-9e28-0ce9d095d94an%40googlegroups.com.


Re: [sqlalchemy] Updating another table in "before-insert" event

2020-10-24 Thread Mike Bayer




On Fri, Oct 23, 2020, at 8:30 PM, ai.rese...@gmail.com wrote:
> 
> Hi all
> 
> I want to update a table row once I create a new row in another table. These 
> 2 tables are in the same database, but no relationship between them
> 
> I use "before_insert" listener for the first table. In this function, I load 
> the target object instance from the second table and try to update it. After 
> update, if I flush the session, I got this error that the session is already 
> flushing which is reasonable. On the other hand, if I don't flush the 
> session, the change on the second table is not applied. I appreciate your 
> kind advice on this issue.

So I would imagine you'd want to use the "after_insert" event here since you 
want to update this row *after* you created the other new row.

when you're in before_insert /after_insert etc., there's a Connection there, 
emit Core update statements on that.  you can't perform session persistence 
operations inside of these functions.

connection.execute(target_table.update().where(target_table.c.id == 
).values(foo='bar'))













> 
> 

> --
> 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/a83bf57a-0c87-479d-89e9-fc009daa7c92n%40googlegroups.com
>  
> .

-- 
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/94751719-67f1-4164-96ec-f8c7b4d60daf%40www.fastmail.com.