On Fri, Mar 29, 2019 at 4:39 PM Jonathan Vanasco <jvana...@gmail.com> 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.

Reply via email to