Re: [sqlalchemy] check for None with == , within join, raises argument error

2018-02-05 Thread Jonathan Vanasco


On Monday, February 5, 2018 at 3:19:40 AM UTC-5, Rajesh Rolo wrote:
>
>
> Thank you. .op() seems to have done the trick. I'm going to go with it as 
> of now. 
>
>>
Please make a test-case of your mistake though, it's important to get this 
figured out and patched if there is a bug. 

-- 
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.


Re: [sqlalchemy] check for None with == , within join, raises argument error

2018-02-05 Thread Mike Bayer
On Feb 4, 2018 4:25 PM, "Jonathan Vanasco"  wrote:



On Sunday, February 4, 2018 at 11:07:49 AM UTC-5, Mike Bayer wrote:
>
> You test for NULL with == None.  I have no idea what your issue is can you
> please share complete mappings, complete stack trace and a reproducible
> example?  Thanks
>

This definitely needs a reproduction testcase to find the correct error as
Mike noted, but if you're stuck in a bind for a temporary fix you can try:

   User.flag.op('IS')(None)


using `.op()` has gotten me out of a lot of problems.


Any examples?  Was hoping to get a bug report out of this.



you should also check the sql emitted, because you may need to
'.self_group()' the or_ elements.

or_(User.flag == None, User.flag != "dnd").self_group()


i haven't been able to create a reliable test case for the above, but there
are a handful of times in postgres queries where my or's haven't been
grouped as expected, leading to a bad query.  i check everything now.

> --
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.


Re: [sqlalchemy] check for None with == , within join, raises argument error

2018-02-05 Thread Rajesh Rolo
Jonathan,

Thank you. .op() seems to have done the trick. I'm going to go with it as 
of now. 

Thanx,
Rajesh


On Monday, February 5, 2018 at 2:55:50 AM UTC+5:30, Jonathan Vanasco wrote:
>
>
>
> On Sunday, February 4, 2018 at 11:07:49 AM UTC-5, Mike Bayer wrote:
>>
>> You test for NULL with == None.  I have no idea what your issue is can 
>> you please share complete mappings, complete stack trace and a reproducible 
>> example?  Thanks
>>
>
> This definitely needs a reproduction testcase to find the correct error as 
> Mike noted, but if you're stuck in a bind for a temporary fix you can try:
>
>User.flag.op('IS')(None)
>
>
> using `.op()` has gotten me out of a lot of problems.
>
> you should also check the sql emitted, because you may need to 
> '.self_group()' the or_ elements. 
>
> or_(User.flag == None, User.flag != "dnd").self_group()
>
>
> i haven't been able to create a reliable test case for the above, but 
> there are a handful of times in postgres queries where my or's haven't been 
> grouped as expected, leading to a bad query.  i check everything now.
>
>>

-- 
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.


Re: [sqlalchemy] check for None with == , within join, raises argument error

2018-02-04 Thread Jonathan Vanasco


On Sunday, February 4, 2018 at 11:07:49 AM UTC-5, Mike Bayer wrote:
>
> You test for NULL with == None.  I have no idea what your issue is can you 
> please share complete mappings, complete stack trace and a reproducible 
> example?  Thanks
>

This definitely needs a reproduction testcase to find the correct error as 
Mike noted, but if you're stuck in a bind for a temporary fix you can try:

   User.flag.op('IS')(None)


using `.op()` has gotten me out of a lot of problems.

you should also check the sql emitted, because you may need to 
'.self_group()' the or_ elements. 

or_(User.flag == None, User.flag != "dnd").self_group()


i haven't been able to create a reliable test case for the above, but there 
are a handful of times in postgres queries where my or's haven't been 
grouped as expected, leading to a bad query.  i check everything now.

>

-- 
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.


Re: [sqlalchemy] check for None with == , within join, raises argument error

2018-02-04 Thread Mike Bayer
You test for NULL with == None.  I have no idea what your issue is can you
please share complete mappings, complete stack trace and a reproducible
example?  Thanks

On Feb 4, 2018 9:53 AM, "Rajesh Rolo"  wrote:

I have a query which tries to get list of users for a particular set of
events which joins with the user table to check if the user is not marked
for a particular flag "dnd" (flag column could have a null value too). The
query goes something like this:

query = session.query(Event.uid).filter(Event.event.in_(event_list)).\
join(User, and_((User.id == Event.uid), \
or_(User.flag == None, User.flag != "dnd")))

It raises an Argument error exception

ArgumentError("Only '=', '!=', 'is_()', 'isnot()' operators can
be used with None/True/False",)

I've tried other possibilities/suggestions (listed below) but still get the
same error:

   - using # noqa
   - checking "User.Flag is None"
   - checking "User.Flag.is_(None)"

In other places, when I'm checking only with the User table without a join,
it seems to work. For eg:

User.query.filter(User.flag == None, User.flag != "dnd").all()

works.

DB being used is postgresql.

How do I check for NULL value within this join?

-- 
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] check for None with == , within join, raises argument error

2018-02-04 Thread Rajesh Rolo


I have a query which tries to get list of users for a particular set of 
events which joins with the user table to check if the user is not marked 
for a particular flag "dnd" (flag column could have a null value too). The 
query goes something like this:

query = session.query(Event.uid).filter(Event.event.in_(event_list)).\
join(User, and_((User.id == Event.uid), \
or_(User.flag == None, User.flag != "dnd")))

It raises an Argument error exception

ArgumentError("Only '=', '!=', 'is_()', 'isnot()' operators can
be used with None/True/False",)

I've tried other possibilities/suggestions (listed below) but still get the 
same error:

   - using # noqa
   - checking "User.Flag is None"
   - checking "User.Flag.is_(None)"

In other places, when I'm checking only with the User table without a join, 
it seems to work. For eg:

User.query.filter(User.flag == None, User.flag != "dnd").all()

works.

DB being used is postgresql.

How do I check for NULL value within this join?

-- 
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.