Re: [sqlalchemy] testing/raising errors for queries that do not filter against themselves

2019-03-30 Thread Jonathan Vanasco
On Friday, March 29, 2019 at 7:35:02 PM UTC-4, Mike Bayer wrote:
>
>
> I'm assuming you mean a double equals sign there.  


Yes. I am embarrassed
 

> I think I was assuming that user would come back with a great success 
> story and this could be either on the wiki or maybe even an ext or a 
> flag you can turn on in the compiler, but I guess he was so satisfied 
> that he never came back and I forgot all about it.So you can only 
> use this on the condition that you report back on its general 
> usability and if it's going to give me grief if I unleash it in the 
> docs. 
>

wow. this looks great.  I've put this on my schedule for Monday. (I was 
also scared that person was me and I forgot all about this, thankfully it 
wasn't!)





 

-- 
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] testing/raising errors for queries that do not filter against themselves

2019-03-29 Thread Mike Bayer
On Fri, Mar 29, 2019 at 4:39 PM Jonathan Vanasco  wrote:
>
> I was going batty trying to figure out why a unit test kept passing, while 
> the functionality was clearly broken.
>
> I eventually realized the problem was a `filter` that didn't apply to the 
> actual query.
>
> The code was essentially this:
>
> result = s.query(Foo).filter(Bar.id = 1)
>
> but it was difficult to tell because the classes looked more like 
> FooVariantApples and FooVariantAardvarks
>
> Is there a way I can configure SqlAlchemy to raise exceptions to queries if 
> the filters apply to a class that is not queried or joined?

I'm assuming you mean a double equals sign there.   Typically, you
just need to have a few more rows in your table during unit tests to
ensure that unwanted rows are not matched.

However!   if you'd like to go crazy, since I had a user who refused
to stop complaining about this some years ago, I wrote them a
cartesian product linter.   Here it is!
https://gist.github.com/zzzeek/c514e2c874fca54df80fc55b680e51c5

I think I was assuming that user would come back with a great success
story and this could be either on the wiki or maybe even an ext or a
flag you can turn on in the compiler, but I guess he was so satisfied
that he never came back and I forgot all about it.So you can only
use this on the condition that you report back on its general
usability and if it's going to give me grief if I unleash it in the
docs.



>
> --
> 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] testing/raising errors for queries that do not filter against themselves

2019-03-29 Thread Jonathan Vanasco
I was going batty trying to figure out why a unit test kept passing, while 
the functionality was clearly broken.

I eventually realized the problem was a `filter` that didn't apply to the 
actual query.

The code was essentially this:

result = s.query(Foo).filter(Bar.id = 1)

but it was difficult to tell because the classes looked more like 
FooVariantApples and FooVariantAardvarks

Is there a way I can configure SqlAlchemy to raise exceptions to queries if 
the filters apply to a class that is not queried or joined?

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