Re: [sqlalchemy] AssertionError seen for queries taking more than 30 seconds to execute

2018-08-28 Thread Mike Bayer
On Tue, Aug 28, 2018 at 7:50 AM, Mohit Agarwal 
wrote:

> Hi,
> We are seeing exceptions:AssertionError being raised when of our APIs has
> a long running query. In code we are rolling back transaction if any error
> is received while committing. Basically we have this general wrapper
>
> try:
>  session.commit()
> except:
>  session.rollback()
>
>
>
> Our sql alchemy version - 1.0.6
> Our database - Azure SQL (sql server)
>


that's a very old SQLAlchemy version, I can't say what the issue is but at
least would need the complete stack trace and the complete error messages
including the "inner" stack trace, e.g. what you are actually catching with
that "except".The session is likely already being rolled back within
the scope of the "commit" and then some state issue is preventing
rollback() from working again.   There have been fixes in the area of
Session state management over the years so the first step would be
upgrading to a 1.1 or 1.2 version of SQLAlchemy to see if that resolves.


>
>
> Stack trace -
> File "/code/api/named_location/resources.py", line 258, in
> create_named_locations_dataclass
> File "/code/api/named_location/operations.py", line 94, in do_create
> File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/scoping.py",
> line 150, in do
> File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py",
> line 754, in rollback
> File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py",
> line 437, in rollback
> File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py",
> line 273, in _restore_snapshot
>
> From the code it looks like it fails here -
> def _restore_snapshot(self, dirty_only=False):
> *assert self._is_transaction_boundary*
> What does it mean, why rollback is failing ?
>
>
>
> Thanks
> Mohit
>
> --
> 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 post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] AssertionError seen for queries taking more than 30 seconds to execute

2018-08-28 Thread Mohit Agarwal
Hi,
We are seeing exceptions:AssertionError being raised when of our APIs has a 
long running query. In code we are rolling back transaction if any error is 
received while committing. Basically we have this general wrapper

try:
 session.commit()
except:
 session.rollback()



Our sql alchemy version - 1.0.6
Our database - Azure SQL (sql server)


Stack trace - 
File "/code/api/named_location/resources.py", line 258, in 
create_named_locations_dataclass
File "/code/api/named_location/operations.py", line 94, in do_create
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/scoping.py", 
line 150, in do
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
line 754, in rollback
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
line 437, in rollback
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/session.py", 
line 273, in _restore_snapshot

>From the code it looks like it fails here - 
def _restore_snapshot(self, dirty_only=False):
*assert self._is_transaction_boundary* 
What does it mean, why rollback is failing ?



Thanks
Mohit

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is already registered

2014-06-26 Thread Dustin Oprea
I'm using SQLAlchemy with web.py, and have used it many times in the past. 
I'm working on a project using gevent/greenlets, and everything has been 
fine for a couple of months, until today.

Suddenly, I'm getting these at a time when I'm not even receiving any 
requests. Does anyone have any advice or steps to troubleshoot?

Traceback (most recent call last):
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
237, in process
return p(lambda: process(processors))
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
565, in processor
h()
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
661, in __call__
self.check(mod)
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
680, in check
reload(mod)
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 58, in module
class Inspector(object):
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 136, in Inspector
@inspection._inspects(Connectable)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, 
line 84, in decorate
registered % type_)
AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is 
already registered

Traceback (most recent call last):
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
237, in process
return p(lambda: process(processors))
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
565, in processor
h()
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
661, in __call__
self.check(mod)
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
680, in check
reload(mod)
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 58, in module
class Inspector(object):
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 136, in Inspector
@inspection._inspects(Connectable)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, 
line 84, in decorate
registered % type_)
AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is 
already registered

Traceback (most recent call last):
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
237, in process
return p(lambda: process(processors))
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
565, in processor
h()
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
661, in __call__
self.check(mod)
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
680, in check
reload(mod)
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 58, in module
class Inspector(object):
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 136, in Inspector
@inspection._inspects(Connectable)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, 
line 84, in decorate
registered % type_)
AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is 
already registered

Traceback (most recent call last):
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
237, in process
return p(lambda: process(processors))
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
565, in processor
h()
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
661, in __call__
self.check(mod)
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
680, in check
reload(mod)
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 58, in module
class Inspector(object):
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 136, in Inspector
@inspection._inspects(Connectable)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, 
line 84, in decorate
registered % type_)
AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is 
already registered

Traceback (most recent call last):
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
237, in process
return p(lambda: process(processors))
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
565, in processor
h()
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
661, in __call__
self.check(mod)
  File /usr/local/lib/python2.7/dist-packages/web/application.py, line 
680, in check
reload(mod)
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 58, in module
class Inspector(object):
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py, 
line 136, in Inspector
@inspection._inspects(Connectable)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, 
line 84, in 

Re: [sqlalchemy] AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is already registered

2014-06-26 Thread Mike Bayer
that looks pretty much like modules are being reloaded in process.   
Either get web.py to not reload the sqlalchemy modules, or if it has
to, then get it to fully load sqlalchemy completely.   I see that
reload(mod) right in the stack trace there.




On 6/26/14, 1:14 PM, Dustin Oprea wrote:
 I'm using SQLAlchemy with web.py, and have used it many times in the
 past. I'm working on a project using gevent/greenlets, and everything
 has been fine for a couple of months, until today.

 Suddenly, I'm getting these at a time when I'm not even receiving any
 requests. Does anyone have any advice or steps to troubleshoot?

 Traceback (most recent call last):
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 237, in process
 return p(lambda: process(processors))
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 565, in processor
 h()
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 661, in __call__
 self.check(mod)
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 680, in check
 reload(mod)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
 class Inspector(object):
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
 @inspection._inspects(Connectable)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
 registered % type_)
 AssertionError: Type class
 'sqlalchemy.engine.interfaces.Connectable' is already registered

 Traceback (most recent call last):
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 237, in process
 return p(lambda: process(processors))
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 565, in processor
 h()
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 661, in __call__
 self.check(mod)
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 680, in check
 reload(mod)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
 class Inspector(object):
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
 @inspection._inspects(Connectable)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
 registered % type_)
 AssertionError: Type class
 'sqlalchemy.engine.interfaces.Connectable' is already registered

 Traceback (most recent call last):
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 237, in process
 return p(lambda: process(processors))
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 565, in processor
 h()
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 661, in __call__
 self.check(mod)
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 680, in check
 reload(mod)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
 class Inspector(object):
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
 @inspection._inspects(Connectable)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
 registered % type_)
 AssertionError: Type class
 'sqlalchemy.engine.interfaces.Connectable' is already registered

 Traceback (most recent call last):
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 237, in process
 return p(lambda: process(processors))
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 565, in processor
 h()
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 661, in __call__
 self.check(mod)
   File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line
 680, in check
 reload(mod)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
 class Inspector(object):
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
 @inspection._inspects(Connectable)
   File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
 registered % type_)
 AssertionError: Type class
 

Re: [sqlalchemy] AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is already registered

2014-06-26 Thread Dustin Oprea
On Jun 26, 2014 1:34 PM, Mike Bayer mike...@zzzcomputing.com wrote:

 that looks pretty much like modules are being reloaded in process.
Either get web.py to not reload the sqlalchemy modules, or if it has to,
then get it to fully load sqlalchemy completely.   I see that
reload(mod) right in the stack trace there.

Sure, but I have a dozen web.py projects, and gave been using it for a
while, and haven't had this issue until yesterday. I thought that too, but
doubt that's it.

Dustin





 On 6/26/14, 1:14 PM, Dustin Oprea wrote:

 I'm using SQLAlchemy with web.py, and have used it many times in the
past. I'm working on a project using gevent/greenlets, and everything has
been fine for a couple of months, until today.

 Suddenly, I'm getting these at a time when I'm not even receiving any
requests. Does anyone have any advice or steps to troubleshoot?

 Traceback (most recent call last):
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 237, in process
 return p(lambda: process(processors))
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 565, in processor
 h()
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 661, in __call__
 self.check(mod)
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 680, in check
 reload(mod)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 58, in module
 class Inspector(object):
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 136, in Inspector
 @inspection._inspects(Connectable)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, line 84,
in decorate
 registered % type_)
 AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable'
is already registered

 Traceback (most recent call last):
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 237, in process
 return p(lambda: process(processors))
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 565, in processor
 h()
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 661, in __call__
 self.check(mod)
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 680, in check
 reload(mod)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 58, in module
 class Inspector(object):
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 136, in Inspector
 @inspection._inspects(Connectable)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, line 84,
in decorate
 registered % type_)
 AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable'
is already registered

 Traceback (most recent call last):
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 237, in process
 return p(lambda: process(processors))
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 565, in processor
 h()
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 661, in __call__
 self.check(mod)
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 680, in check
 reload(mod)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 58, in module
 class Inspector(object):
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 136, in Inspector
 @inspection._inspects(Connectable)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, line 84,
in decorate
 registered % type_)
 AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable'
is already registered

 Traceback (most recent call last):
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 237, in process
 return p(lambda: process(processors))
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 565, in processor
 h()
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 661, in __call__
 self.check(mod)
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 680, in check
 reload(mod)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 58, in module
 class Inspector(object):
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
line 136, in Inspector
 @inspection._inspects(Connectable)
   File
/usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py, line 84,
in decorate
 registered % type_)
 AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable'
is already registered

 Traceback (most recent call last):
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 237, in process
 return p(lambda: process(processors))
   File /usr/local/lib/python2.7/dist-packages/web/application.py,
line 565, in processor
 h()
   File 

Re: [sqlalchemy] AssertionError: Type class 'sqlalchemy.engine.interfaces.Connectable' is already registered

2014-06-26 Thread Mike Bayer

On 6/26/14, 1:49 PM, Dustin Oprea wrote:


 On Jun 26, 2014 1:34 PM, Mike Bayer mike...@zzzcomputing.com
 mailto:mike...@zzzcomputing.com wrote:
 
  that looks pretty much like modules are being reloaded in
 process.Either get web.py to not reload the sqlalchemy modules,
 or if it has to, then get it to fully load sqlalchemy completely.  
 I see that reload(mod) right in the stack trace there.

 Sure, but I have a dozen web.py projects, and gave been using it for a
 while, and haven't had this issue until yesterday. I thought that too,
 but doubt that's it.


I guarantee you that is it - maybe it was not being called on this
particular module or combination of modules.  module reloading is bad IMHO.




 Dustin
 
 
 
 
 
  On 6/26/14, 1:14 PM, Dustin Oprea wrote:
 
  I'm using SQLAlchemy with web.py, and have used it many times in
 the past. I'm working on a project using gevent/greenlets, and
 everything has been fine for a couple of months, until today.
 
  Suddenly, I'm getting these at a time when I'm not even receiving
 any requests. Does anyone have any advice or steps to troubleshoot?
 
  Traceback (most recent call last):
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 237,
 in process
  return p(lambda: process(processors))
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 565,
 in processor
  h()
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 661,
 in __call__
  self.check(mod)
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 680,
 in check
  reload(mod)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
  class Inspector(object):
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
  @inspection._inspects(Connectable)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
  registered % type_)
  AssertionError: Type class
 'sqlalchemy.engine.interfaces.Connectable' is already registered
 
  Traceback (most recent call last):
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 237,
 in process
  return p(lambda: process(processors))
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 565,
 in processor
  h()
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 661,
 in __call__
  self.check(mod)
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 680,
 in check
  reload(mod)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
  class Inspector(object):
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
  @inspection._inspects(Connectable)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
  registered % type_)
  AssertionError: Type class
 'sqlalchemy.engine.interfaces.Connectable' is already registered
 
  Traceback (most recent call last):
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 237,
 in process
  return p(lambda: process(processors))
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 565,
 in processor
  h()
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 661,
 in __call__
  self.check(mod)
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 680,
 in check
  reload(mod)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
  class Inspector(object):
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
  @inspection._inspects(Connectable)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
  registered % type_)
  AssertionError: Type class
 'sqlalchemy.engine.interfaces.Connectable' is already registered
 
  Traceback (most recent call last):
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 237,
 in process
  return p(lambda: process(processors))
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 565,
 in processor
  h()
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 661,
 in __call__
  self.check(mod)
File
 /usr/local/lib/python2.7/dist-packages/web/application.py, line 680,
 in check
  reload(mod)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 58, in module
  class Inspector(object):
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/reflection.py,
 line 136, in Inspector
  @inspection._inspects(Connectable)
File
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/inspection.py,
 line 84, in decorate
  registered % 

Re: [sqlalchemy] AssertionError

2014-03-19 Thread lars van gemerden
clear and bug found .. thanks



On Tuesday, March 18, 2014 4:51:36 PM UTC+1, Michael Bayer wrote:

 it means this:

 a1 = A(id=1)
 session.add(a1)
 session.commit()

 a2 = A(id=1)
 session.add(a2)   # — error


 On Mar 18, 2014, at 9:59 AM, lars van gemerden 
 la...@rational-it.comjavascript: 
 wrote:

 Hi all,

 Does anyone know hoe to interpret the following error?

 AssertionError: A conflicting state is already present in the identity 
 map for key (class 'models.data.database.Keuze', (1,))

 Cheers, Lars

 -- 
 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 javascript:.
 To post to this group, send email to sqlal...@googlegroups.comjavascript:
 .
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.




-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] AssertionError

2014-03-18 Thread lars van gemerden
Hi all,

Does anyone know hoe to interpret the following error?

AssertionError: A conflicting state is already present in the identity 
map for key (class 'models.data.database.Keuze', (1,))

Cheers, Lars

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] AssertionError

2014-03-18 Thread Michael Bayer
it means this:

a1 = A(id=1)
session.add(a1)
session.commit()

a2 = A(id=1)
session.add(a2)   # -- error


On Mar 18, 2014, at 9:59 AM, lars van gemerden l...@rational-it.com wrote:

 Hi all,
 
 Does anyone know hoe to interpret the following error?
 
 AssertionError: A conflicting state is already present in the identity 
 map for key (class 'models.data.database.Keuze', (1,))
 
 Cheers, Lars
 
 -- 
 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 post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] AssertionError When Removing Children For Association Object

2014-01-09 Thread Russell Holloway



 you need to put a cascade rule on Page.user_relationships, such that when 
 you remove a Page_to_User from the collection, it’s marked as deleted, 
 instead of SQLAlchemy setting the page_id foreign key to NULL, which is 
 invalid here b.c. that column is part of the primary key (and hence the 
 error).   Page_to_User can’t exist in the database without being referred 
 to by a Page object since the primary key would be NULL.

 the delete-orphan cascade is introduced at:


 http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#configuring-delete-delete-orphan-cascade

 and some more information at: 
 http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#deleting-from-collections



Can you help me understand why a cascade rule is needed? I have read the 
documentation you linked to but still have trouble grasping why it is 
needed. I understand it would make sense if I deleted a page, that it 
should cascade on delete to page_to_user because now the FK page_id is no 
longer valid - the page doesn't exist, so it cannot possibly be mapped 
anywhere.

What I'm having trouble understanding is what is cascading from what to 
what when deleting from this page.user_relationships collection. It doesn't 
cascade from page, because I am not deleting any pages, and it doesn't 
cascade from users, because no users are deleted. The only thing being 
deleted is the mapping itself.

In the database table definition, there doesn't have to be any cascade 
settings at all for the constraints and it will still work fine. Maybe it's 
purely a SQLAlchemy thing and how it's designed for some reason? I would 
just like to understand better for future development. Thanks in advance.

-Russ

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] AssertionError When Removing Children For Association Object

2014-01-09 Thread Michael Bayer

On Jan 9, 2014, at 10:02 AM, Russell Holloway russ.d.hollo...@gmail.com wrote:

 
 you need to put a cascade rule on Page.user_relationships, such that when you 
 remove a Page_to_User from the collection, it’s marked as deleted, instead of 
 SQLAlchemy setting the page_id foreign key to NULL, which is invalid here 
 b.c. that column is part of the primary key (and hence the error).   
 Page_to_User can’t exist in the database without being referred to by a Page 
 object since the primary key would be NULL.
 
 the delete-orphan cascade is introduced at:
 
 http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#configuring-delete-delete-orphan-cascade
 
 and some more information at: 
 http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#deleting-from-collections
 
 
 
 Can you help me understand why a cascade rule is needed? I have read the 
 documentation you linked to but still have trouble grasping why it is needed. 
 I understand it would make sense if I deleted a page, that it should cascade 
 on delete to page_to_user because now the FK page_id is no longer valid - the 
 page doesn't exist, so it cannot possibly be mapped anywhere.

OK so, you have:

Page.user_relationships - collection of PageToUser

PageToUser - single User

then, you are saying :

some_page.user_relationships = []
session.flush()

What SQL would you expect this to produce?  After a flush, what would the rows 
in your page_to_user table look like?


 
 What I'm having trouble understanding is what is cascading from what to what 
 when deleting from this page.user_relationships collection. It doesn't 
 cascade from page, because I am not deleting any pages, and it doesn't 
 cascade from users, because no users are deleted.

“delete-orphan” means when an item is removed from a collection, in this case a 
PageToUser object, it is marked as deleted.


 In the database table definition, there doesn't have to be any cascade 
 settings at all for the constraints and it will still work fine.

OK you need to show what “works fine” is - how the Page.user_relationships 
collection can be empty on a particular Page object, yet there are PageToUser 
objects in the database which refer to that Page (or if you think the 
PageToUser row still exists, but doesn’t point to any Page, show me how that 
looks).  What’s in the database?




signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: [sqlalchemy] AssertionError When Removing Children For Association Object

2014-01-09 Thread Russell Holloway



 OK so, you have:

 Page.user_relationships - collection of PageToUser

 PageToUser - single User

 then, you are saying :

 some_page.user_relationships = []
 session.flush()

 What SQL would you expect this to produce?  After a flush, what would the 
 rows in your page_to_user table look like?


I would expect it to delete entries, resulting in no rows for that page_id
DELETE FROM Page_To_User WHERE page_id = ?

Perhaps it tries this instead?
UPDATE Page_To_User SET page_id = NULL WHERE page_id = ?

 


 What I'm having trouble understanding is what is cascading from what to 
 what when deleting from this page.user_relationships collection. It doesn't 
 cascade from page, because I am not deleting any pages, and it doesn't 
 cascade from users, because no users are deleted. 


 “delete-orphan” means when an item is removed from a collection, in this 
 case a PageToUser object, it is marked as deleted.


So by default does page.user_relationships call the above UPDATE call and 
set to null or something?
 

 In the database table definition, there doesn't have to be any cascade 
 settings at all for the constraints and it will still work fine. 


 OK you need to show what “works fine” is - how the Page.user_relationships 
 collection can be empty on a particular Page object, yet there are 
 PageToUser objects in the database which refer to that Page (or if you 
 think the PageToUser row still exists, but doesn’t point to any Page, show 
 me how that looks).  What’s in the database?


In my mind, Page.user_relationship is a collection of PageToUser objects, 
so by emptying that collection, all those objects are deleted from 
Page_To_User. It doesn't have anything to do with the Page object itself 
though - only the associations in PageToUser.

The following table definitions work without the CASCADE being used on FK 
at all (it may prevent deletions of Page or User rows due to FK 
constraints, but not in this example since we don't ever delete those rows).

CREATE TABLE Page (
  int page_id not null auto increment,
  varchar(255) title,
  primary key (page_id)
) Engine=InnoDB;

CREATE TABLE User (
  int user_id not null auto increment,
  varchar(255) name,
  primary key (user_id)
) Engine=InnoDB;

CREATE TABLE Page_To_User (
  int page_id not null,
  int user_id not null,
  int relationship_id not null,
  primary key (page_id, user_id, relationship_id),
  foreign key (page_id) references Page(page_id),
  foreign key (user_id) references User(user_id)
) Engine=InnoDB;

Above, there isn't any ON DELETE CASCADE specified for any of the foreign 
keys. My understanding is if there were, 

  foreign key (page_id) references Page(page_id) ON DELETE CASCADE

then, if I delete row with that page_id from Page, then it will cascade 
from Page to Page_To_User and delete the appropriate row. If ON DELETE 
CASCADE is missing, it will complain if I try to delete that Page row, 
because there are FK constraints.

But issuing a simple ' DELETE FROM Page_To_User WHERE page_id = ? ' 
shouldn't require any cascading, at least in SQL. Maybe the cascade keyword 
in SQLAlchemy does not exactly mean cascade on a table definition?

-Russ

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] AssertionError When Removing Children For Association Object

2014-01-09 Thread Michael Bayer

On Jan 9, 2014, at 10:31 AM, Russell Holloway russ.d.hollo...@gmail.com wrote:

 
 OK so, you have:
 
 Page.user_relationships - collection of PageToUser
 
 PageToUser - single User
 
 then, you are saying :
 
 some_page.user_relationships = []
 session.flush()
 
 What SQL would you expect this to produce?  After a flush, what would the 
 rows in your page_to_user table look like?
 
 
 I would expect it to delete entries, resulting in no rows for that page_id
 DELETE FROM Page_To_User WHERE page_id = ?
 
 Perhaps it tries this instead?
 UPDATE Page_To_User SET page_id = NULL WHERE page_id = ?

You are correct in both cases.So if you follow the instructions for 
delete-orphan cascade as previously mentioned here: 

http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#configuring-delete-delete-orphan-cascade

the rows will be deleted instead.

Perhaps you’re being thrown off by the fact that an ORM level cascade is set on 
the *opposite* side as a FOREIGN KEY cascade in SQL, but that is how it works.  
  The Page.user_relationships collection is what indicates the handling of 
PageToUser objects.

If you want to see the origin of the “CASCADE” settings, they come from 
Hibernate: 
http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/example-parentchild.html
 .




signature.asc
Description: Message signed with OpenPGP using GPGMail


[sqlalchemy] AssertionError When Removing Children For Association Object

2014-01-08 Thread Russell Holloway
Hello all, 

I keep hitting an assertion error, Dependency Rule Tried To Blank Out 
Primary Key... when trying to remove all children using an association 
object.

My situation seems very similar 
to https://groups.google.com/forum/#!topic/sqlalchemy/3g4__pFHZTs

However, based on Michaels response, it sounds like we must delete both 
objects, which I don't want to do since it is a many-many relationship. 
Below is a simple equivalent to my code:

Page(Object):
  page_id = Column(Integer, primary_key = True)
  title = Column(String)

  user_relationships = relationship(Page_to_User)

User(Object):
  user_id = Column(Integer, primary_key = True)
  name = Column(String)

Page_to_User(Object):

  page_id = Column(Integer, ForeignKey(Page.page_id), primary_key = True)
  user_id = Column(Integer, ForeignKey(User.user_id), primary_key = True)
  relationship_type = (Integer, ForeignKey(Relationship.type_id), 
primary_key = True)

  page = relationship(Page)
  user = relationship(User)



Assuming page1 object has many users tied to it, and I want to unassociate 
them all...

print page1.user_relationships # populated with stuff, works as expected
page1.user_relationships = []
session.flush() # error here

My understanding is it page1.user_relationships is populated correctly due 
to the FK set on Page_to_User Association object. Somehow, it's getting the 
'tried to blank out' error on the Page_to_User table...

In the link above, Michael's write up sounds like the cause is if I try to 
delete the Page object, which references Page_to_User, which has foreign 
key to Page. It then tries to set page_id to null on Page_to_Actor due to 
FK constraints and ultimately fails. However, I'm not trying to delete the 
Page object here - just the associations to User. The Page stays. The User 
objects also stay. They just are not linked anymore...

Can someone help explain why I still trigger this issue? I can make it go 
away setting viewonly=True on the user_relationships relationship() call, 
but I don't want it view only - I want to be able to update and work with 
those objects as usual.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [sqlalchemy] AssertionError When Removing Children For Association Object

2014-01-08 Thread Michael Bayer

On Jan 8, 2014, at 5:41 PM, Russell Holloway russ.d.hollo...@gmail.com wrote:

 Hello all, 
 
 I keep hitting an assertion error, Dependency Rule Tried To Blank Out 
 Primary Key... when trying to remove all children using an association 
 object.
 
 My situation seems very similar to 
 https://groups.google.com/forum/#!topic/sqlalchemy/3g4__pFHZTs
 
 However, based on Michaels response, it sounds like we must delete both 
 objects, which I don't want to do since it is a many-many relationship. Below 
 is a simple equivalent to my code:
 
 Page(Object):
   page_id = Column(Integer, primary_key = True)
   title = Column(String)
 
   user_relationships = relationship(Page_to_User)
 
 User(Object):
   user_id = Column(Integer, primary_key = True)
   name = Column(String)
 
 Page_to_User(Object):
 
   page_id = Column(Integer, ForeignKey(Page.page_id), primary_key = True)
   user_id = Column(Integer, ForeignKey(User.user_id), primary_key = True)
   relationship_type = (Integer, ForeignKey(Relationship.type_id), primary_key 
 = True)
 
   page = relationship(Page)
   user = relationship(User)


you need to put a cascade rule on Page.user_relationships, such that when you 
remove a Page_to_User from the collection, it’s marked as deleted, instead of 
SQLAlchemy setting the page_id foreign key to NULL, which is invalid here b.c. 
that column is part of the primary key (and hence the error).   Page_to_User 
can’t exist in the database without being referred to by a Page object since 
the primary key would be NULL.

the delete-orphan cascade is introduced at:

http://docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html#configuring-delete-delete-orphan-cascade

and some more information at: 
http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#deleting-from-collections




 
 -- 
 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 post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/groups/opt_out.



signature.asc
Description: Message signed with OpenPGP using GPGMail


[sqlalchemy] AssertionError: Dependency rule tried to blank-out primary key column with Elixir

2008-05-21 Thread kremlan

I've posted the following question on the Elixir group and they sent
me here.

My setup

##
# Tables
##
roles = Table('roles', meta,
Column('id', Integer, primary_key=True),
Column('name', String(25))
)

users = Table('users', meta,
Column('id', Integer, primary_key=True),
Column('username', String(125)),
Column('password', String(125)),

)

users_roles = Table('users_roles', meta,
Column('user_id', Integer, primary_key=True),
Column('role_id', Integer, primary_key=True),

ForeignKeyConstraint(['user_id'], ['users.id']),
ForeignKeyConstraint(['role_id'], ['roles.id'])
)

##
# Elixir models
##

class UserRole(Entity):
using_options(tablename='users_roles', autoload=True)
user = ManyToOne('User', colname='user_id')
role = ManyToOne('Role', colname='role_id')

class Role(Entity):
using_options(tablename='roles', autoload=True)
users_roles = OneToMany('UserRole')
users = AssociationProxy('users_roles', 'user')

class User(Entity):
using_options(tablename='users', autoload=True)
users_roles = OneToMany('UserRole')
roles = AssociationProxy('users_roles', 'role')

This setup works fine for reading but not for updating or deleting.

I was able to then get the append method working via the following

def _create_ur_by_role(role):
return UserRole(role=role)

in class User:
roles = AssociationProxy('users_roles', 'role',
creator=_create_ur_by_role)

I am still unable to delete roles. Example:
me.roles.pop() -- works fine
session.flush()

results in...

AssertionError: Dependency rule tried to blank-out primary key column
'users_roles.user_id'

I have tried adding ondelete='cascade' to the UserRole model. This
caused no change.

Any help will be greatly appreciated

-brad

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---