-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using date_part on an aliased field generates new alias #916
Comments
I'm confused...what's different in the 2nd and 3rd queries? I can see that in the first it uses t3 for the alias, but don't understand why it uses t4 in the last query. |
Oops, I see: it's using Person in the second example query. I swear I looked at them for a minute and didn't see that. Ok, makes sense. |
This is a stab at an implementation. What do you think? |
I just tested the example and tested it in my project and I can now remove a lot of work-arounds! Keep up the awesome work! |
This is fixed in 3.0a, commit: f81a30b |
When using the
date_part
functionality (and others, e.g.contains_any
in ArrayField), the field is passed asself
. This works beautifully if you are using the model it is defined in, but, when using it on an aliased table, it generates a new alias.Below is a very crude example from how I found this "problem". This first query shows that the part of the query that will be constructed works when called with the aliased field:
fn.DATE_PART('year', Client.birth) > 1980)
.Calling
Client.birth.year
is what is generating the problem here, as it will refer to thePerson
model instead of theClient
alias, generating the fourth alias. Would I not aliasOwner
, but use thePerson
model, it would construct the where part based on that alias, instead of theClient
.Here are the two generated queries by peewee.
The exception that was caused by the third query:
The text was updated successfully, but these errors were encountered: