Skip to content

fix QuerySet.annotate() crash with combined expression #80

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

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion django_mongodb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _make_result(self, entity, columns):
if column_alias is not None and column_alias != self.collection_name
else entity
)
result.append(obj.get(name, col.field.get_default()))
result.append(obj.get(name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, maybe is time to do obj[name] because None is a value, and returning it is a population ? or I am missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's better to return None rather than fail with an exception here if a field doesn't exist in the document. For example, if a field is added to an existing model, we might not add that field to existing documents.

Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔 , well so we are not managing migrations as the SQLs do, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. Most migration operations are no-op, at least for now.

return result

def check_query(self):
Expand Down
5 changes: 0 additions & 5 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ def django_test_expected_failures(self):
"timezones.tests.NewDatabaseTests.test_query_annotation",
},
"QuerySet.annotate() has some limitations.": {
# annotate() with combined expressions doesn't work:
# 'WhereNode' object has no attribute 'field'
"lookup.tests.LookupQueryingTests.test_combined_annotated_lookups_in_filter",
"lookup.tests.LookupQueryingTests.test_combined_annotated_lookups_in_filter_false",
"lookup.tests.LookupQueryingTests.test_combined_lookups",
# Invalid $project :: caused by :: Unknown expression $count,
"annotations.tests.NonAggregateAnnotationTestCase.test_combined_expression_annotation_with_aggregation",
"annotations.tests.NonAggregateAnnotationTestCase.test_combined_f_expression_annotation_with_aggregation",
Expand Down