Re: [sqlalchemy] Exception on '.refresh' for certain objects - state.load_path Tuple is empty

2021-03-08 Thread Gmoney
Looks like that did the trick!  Should have tried that first, but got lazy 
when conda was resisting my update attempts earlier.
Thank you
On Monday, March 8, 2021 at 4:38:13 PM UTC-5 Mike Bayer wrote:

> it looks like a bug unless you are manipulating the InstanceState.   I 
> would upgrade to SQLAlchemy 1.3.23 first to make sure it hasn't been fixed.
>
>
>
> On Mon, Mar 8, 2021, at 1:09 PM, Gmoney wrote:
>
> On python 3.7 SQLAlchemy 1.3.13
> I'm running into an issue when doing a session.refresh(orm_object) where 
> for certain objects it throws an exception because in line 709 of 
> orm/loading.py, the 'state.load_path' is an empty tuple.  Attached the 
> relevant snippet of the stack dump below.
>
> This was simple test with no actual changes:  
> task = Task.query.filter(blah).one()
> session.refresh(task)
> Again it works for some, not for others.
>
> Is there was something obvious that might cause this - perhaps I'm 
> misunderstanding how refresh works?  We have numerous relationships on the 
> model that often refer to the same table (multiple 'user_id' fk 
> references).  This hasn't causes us any other issues, but it's worth noting.
>
> I will try to pare down the model to isolate what the cause is, and follow 
> up with a test case if I can.  But wanted to see if it was anything obvious 
> before I dig too deep.
>
>   File "/-/lib/python3.7/site-packages/sqlalchemy/orm/loading.py", line 
> 709, in _populate_full
>
> elif load_path != state.load_path:
>
>   File "-/lib/python3.7/site-packages/sqlalchemy/orm/path_registry.py", 
> line 63, in __eq__
>
> return other is not None and self.path == other.path
>
> AttributeError: 'tuple' object has no attribute 'path'
>
>  
>
>
>
>
> -- 
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/007a8cae-33bc-4b5f-bdf3-e8abe1dee358n%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/9a8cd7e3-1c30-48be-81af-7a0ff4d8a5acn%40googlegroups.com.


Re: [sqlalchemy] Exception on '.refresh' for certain objects - state.load_path Tuple is empty

2021-03-08 Thread Mike Bayer
it looks like a bug unless you are manipulating the InstanceState.   I would 
upgrade to SQLAlchemy 1.3.23 first to make sure it hasn't been fixed.



On Mon, Mar 8, 2021, at 1:09 PM, Gmoney wrote:
> On python 3.7 SQLAlchemy 1.3.13
> I'm running into an issue when doing a session.refresh(orm_object) where for 
> certain objects it throws an exception because in line 709 of orm/loading.py, 
> the 'state.load_path' is an empty tuple.  Attached the relevant snippet of 
> the stack dump below.
> 
> This was simple test with no actual changes:  
> task = Task.query.filter(blah).one()
> session.refresh(task)
> Again it works for some, not for others.
> 
> Is there was something obvious that might cause this - perhaps I'm 
> misunderstanding how refresh works?  We have numerous relationships on the 
> model that often refer to the same table (multiple 'user_id' fk references).  
> This hasn't causes us any other issues, but it's worth noting.
> 
> I will try to pare down the model to isolate what the cause is, and follow up 
> with a test case if I can.  But wanted to see if it was anything obvious 
> before I dig too deep.
> 
>   File "/-/lib/python3.7/site-packages/sqlalchemy/orm/loading.py", line 709, 
> in _populate_full

> elif load_path != state.load_path:

>   File "-/lib/python3.7/site-packages/sqlalchemy/orm/path_registry.py", line 
> 63, in __eq__

> return other is not None and self.path == other.path

> AttributeError: 'tuple' object has no attribute 'path'

>  

> 
> 
> 
> 

> -- 
> 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/007a8cae-33bc-4b5f-bdf3-e8abe1dee358n%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/4ce8cc26-9800-483a-a365-02a9b96767f6%40www.fastmail.com.


Re: [sqlalchemy] Supporting Function Indexes on a Minimum Sqlite Version

2021-03-08 Thread Mike Bayer


On Mon, Mar 8, 2021, at 12:06 PM, 'Jonathan Vanasco' via sqlalchemy wrote:
> I have a project that, in a few rare situations, may run on a version of 
> sqlite that does not support function indexes, and "need" to run a unique 
> index on `lower(name)`.  For simplicity, I'll just use a normal index on 
> correct systems,
> 
> I'm trying to figure out the best way to implement this.
> 
> 1. in terms of sqlite3, what is the best way to access the version Sqlalchemy 
> is using?  the import is in a classmethod, and could either be pysqlite2 or 
> sqlite3?  i seriously doubt anyone would deploy with pysqlite2, but I feel 
> like I should do things the right way.

you'd get this from the dbapi:

>>> from sqlalchemy import create_engine 
>>> e = create_engine("sqlite://")
>>> e.dialect.dbapi.sqlite_version
'3.34.1'




> 
> 2. What is the best way to implement this contextual switch?  I thought about 
> a `expression.FunctionElement` with custom `@compiles`.

yeah that is probably the best approach

from sqlalchemy.sql import expression
from sqlalchemy.ext.compiler import compiles

class maybe_lower(expression.FunctionElement):
type = String()

@compiles(maybe_lower, 'sqlite')
def sl_maybe_lower(element, compiler, **kw):
args = list(element.clauses)
if compiler.dialect.dbapi_version < ...:
return "LOWER(%s)" % (compiler.process(args[0], **kw))
else:
return compiler.process(args[0], **kw)

@compiles(maybe_lower)
def default_maybe_lower(element, compiler, **kw):
args = list(element.clauses)
return compiler.process(args[0], **kw)




> 

> -- 
> 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/99598f81-3851-4f2c-988c-1560d2f5e906n%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/a4a601f5-b3db-400e-97e7-9efbe8556568%40www.fastmail.com.


[sqlalchemy] Exception on '.refresh' for certain objects - state.load_path Tuple is empty

2021-03-08 Thread Gmoney
On python 3.7 SQLAlchemy 1.3.13
I'm running into an issue when doing a session.refresh(orm_object) where 
for certain objects it throws an exception because in line 709 of 
orm/loading.py, the 'state.load_path' is an empty tuple.  Attached the 
relevant snippet of the stack dump below.

This was simple test with no actual changes:  
task = Task.query.filter(blah).one()
session.refresh(task)
Again it works for some, not for others.

Is there was something obvious that might cause this - perhaps I'm 
misunderstanding how refresh works?  We have numerous relationships on the 
model that often refer to the same table (multiple 'user_id' fk 
references).  This hasn't causes us any other issues, but it's worth noting.

I will try to pare down the model to isolate what the cause is, and follow 
up with a test case if I can.  But wanted to see if it was anything obvious 
before I dig too deep.

  File "/-/lib/python3.7/site-packages/sqlalchemy/orm/loading.py", line 
709, in _populate_full

elif load_path != state.load_path:

  File "-/lib/python3.7/site-packages/sqlalchemy/orm/path_registry.py", 
line 63, in __eq__

return other is not None and self.path == other.path

AttributeError: 'tuple' object has no attribute 'path'

 


-- 
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/007a8cae-33bc-4b5f-bdf3-e8abe1dee358n%40googlegroups.com.


[sqlalchemy] Supporting Function Indexes on a Minimum Sqlite Version

2021-03-08 Thread 'Jonathan Vanasco' via sqlalchemy
I have a project that, in a few rare situations, may run on a version of 
sqlite that does not support function indexes, and "need" to run a unique 
index on `lower(name)`.  For simplicity, I'll just use a normal index on 
correct systems,

I'm trying to figure out the best way to implement this.

1. in terms of sqlite3, what is the best way to access the version 
Sqlalchemy is using?  the import is in a classmethod, and could either be 
pysqlite2 or sqlite3?  i seriously doubt anyone would deploy with 
pysqlite2, but I feel like I should do things the right way.

2. What is the best way to implement this contextual switch?  I thought 
about a `expression.FunctionElement` with custom `@compiles`.

-- 
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/99598f81-3851-4f2c-988c-1560d2f5e906n%40googlegroups.com.