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

Conversation

timgraham
Copy link
Collaborator

@timgraham timgraham commented Jul 12, 2024

This fallback came from the inital commit of djangotoolbox, however, I don't think it's a good idea to populate model data that's not in the database.

@timgraham timgraham force-pushed the combined-expression-crash branch from dce83f4 to 342d16d Compare July 15, 2024 22:38
@timgraham timgraham marked this pull request as ready for review July 15, 2024 22:53
@timgraham timgraham requested a review from WaVEV July 15, 2024 22:56
@@ -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.

Copy link
Collaborator

@WaVEV WaVEV left a comment

Choose a reason for hiding this comment

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

LGTM

@timgraham timgraham merged commit 342d16d into mongodb:main Jul 16, 2024
3 checks passed
@timgraham timgraham deleted the combined-expression-crash branch July 16, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants