On Tuesday, 10 June 2014 00:48:14 UTC+1, Josh Smeaton wrote:
>
> > However, I think having some special case code in filter(), annotate() 
> and anything else that takes expressions would be OK
>
> I strongly disagree with this. Expressions are context insensitive at the 
> moment, which means they can be used anywhere. If we start externalising 
> behaviour based on the context of use, it'll lead us to some very confusing 
> code and a tonne of special cases.
>

I mean that we would verify __neg__ hadn't been used in the context of 
filter() etc. This doesn't change behaviour for filter(), it just provides 
additional error checking.
 

> It would be slightly better if you could check the context from the 
> `prepare()` method (are we preparing order_by or not),
>

That would be a good way to address it, I think. We are calling prepare() 
for order_by already. We could add a parameter prepare(..., 
allow_ordering=False) and throw an exception for non-default ordering 
unless allow_ordering was set to True.
 

> but then I think we'll run into issues where the prepare breaks for 3rd 
> party backends - by checking private data.
>

I'm not sure what kind of problem you're thinking about here (I'm pretty 
new to this code). Can you give an example?


> - should expressions in order_by support random ordering (?) ? I don't 
> think so, but I haven't ever had a need for random ordering so I'm not sure.
>

Assuming we're not deprecating the order_by('?') syntax (which nobody has 
suggested, I think) I don't see any benefit to integrating expressions with 
random ordering. Random ordering can't usefully be combined with function 
application.

Actually, the possibility of COALESCE(foobar, RANDOM()) just occurred to me 
- I don't know if that's legal.
 

> - could we reduce the complexity of the order_by machinery by forcing all 
> arguments (internally) to be expressions? `order_by('field_a') -> 
> order_by(F('field_a'))` etc
>

I think you're right, though we'd have to be a bit careful that '?' was 
left alone and not expanded to F('?'). I don't have time to try it just 
now, but I'll look at it tomorrow. I'm a bit worried that there's a lot of 
special cases handled by the SQLCompiler.get_ordering() that might not work 
nicely as expressions, but I guess I'll find out.

Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/2259b502-6104-47e7-9fa1-aef599286044%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to