Skip to content
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

Add output_field to preserved_order CASE #381

Merged
merged 1 commit into from Oct 31, 2021

Conversation

dhvcc
Copy link
Contributor

@dhvcc dhvcc commented Oct 19, 2021

Hi, this PR adds output_field to ensure everything's right

I'm not really sure how nobody encountered this, but without specifying output_field I was getting errors while annotating. Here's my code:

In [3]: BookDocument.search().query("fuzzy", title='qwerty').to_queryset().annotate(a=ArrayAgg("person_relations__per
   ...: son__name"))
... ElasticsearchWarning: Elasticsearch built-in security features are not enabled. ..
Out[3]: <repr-error 'Cannot resolve expression type, unknown output_field'>

In [4]: Book.objects.filter(title='qwerty').annotate(a=ArrayAgg("person_relations__person__name"))
Out[4]: <QuerySet []>

In [5]: BookDocument.search().query("fuzzy", title='qwerty').to_queryset().annotate(a=F("person_relations__person__na
   ...: me"))
Out[5]: <QuerySet []>

Notice, how this only happens when using ArrayAgg aggregation from django.contrib.postgres.aggregates

Deps

  • django: 3.1
  • django-elasticsearch-dsl: 7.2.0
  • elasticsearch: 7.15.1
  • elasticsearch-dsl: 7.4.0
  • (docker)postgres: 12

@dhvcc
Copy link
Contributor Author

dhvcc commented Oct 19, 2021

May be it has something to do with the way ArrayAgg treats other annotations, but I'm not that interested in going that deep

@dhvcc dhvcc force-pushed the bug/to_queryset-output-field branch from 257ab15 to 106c5b9 Compare October 22, 2021 15:13
@dhvcc dhvcc force-pushed the bug/to_queryset-output-field branch from 106c5b9 to 53598a3 Compare October 22, 2021 16:50
@codecov-commenter
Copy link

Codecov Report

Merging #381 (8c3784a) into master (1b33fb0) will decrease coverage by 0.13%.
The diff coverage is 100.00%.

❗ Current head 8c3784a differs from pull request most recent head 53598a3. Consider uploading reports for the commit 53598a3 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #381      +/-   ##
==========================================
- Coverage   67.81%   67.67%   -0.14%     
==========================================
  Files          12       12              
  Lines         755      758       +3     
==========================================
+ Hits          512      513       +1     
- Misses        243      245       +2     
Impacted Files Coverage Δ
django_elasticsearch_dsl/search.py 81.48% <100.00%> (-6.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b33fb0...53598a3. Read the comment docs.

@safwanrahman
Copy link
Collaborator

Can you share the SQL Query it is making? So it is easier to undersrtand

Copy link
Collaborator

@safwanrahman safwanrahman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be merged as it does not break any current functionality. It is better to be explicit

@safwanrahman safwanrahman merged commit c0612d6 into django-es:master Oct 31, 2021
@dhvcc
Copy link
Contributor Author

dhvcc commented Nov 1, 2021

@safwanrahman Hey, sorry I didn't have time to provide the SQL part, but basically it's the same SQL as usual
Thanks for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants