Skip to content

fix incorrect GenericRelation joining #130

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
Sep 27, 2024

Conversation

WaVEV
Copy link
Collaborator

@WaVEV WaVEV commented Sep 17, 2024

By adding support for Field.get_extra_restriction().

@WaVEV WaVEV requested a review from timgraham September 17, 2024 10:29
Jibola
Jibola previously requested changes Sep 17, 2024
Copy link
Contributor

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

Great work! Left commentary to get clarification on things

Comment on lines 46 to 47
repository: 'wavev/django'
ref: 'add-support-join-extra-conditions'
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine this should be reverted

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It will.

@@ -0,0 +1,30 @@
from bson import ObjectId, errors
Copy link
Contributor

Choose a reason for hiding this comment

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

is this file a required part of the change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This new field was used in the django library when a new model is created, not here. But we will handle those fields as string for now, so this field is not longer needed.

columns = []
for expr in extra.leaves():
if hasattr(expr, "lhs") and isinstance(expr.lhs, Col):
columns.append((expr.lhs, len(lhs_fields)))
Copy link
Contributor

Choose a reason for hiding this comment

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

To confirm, we use len(lhs_fields) because expr.lhs will now be the newest column index, thus equal to len(lhs_fields)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is.

columns.append((expr.lhs, len(lhs_fields)))
lhs_fields.append(expr.lhs.as_mql(compiler, connection))
if hasattr(expr, "rhs") and isinstance(expr.rhs, Col):
columns.append((expr.rhs, None))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does rhs not get the same as lhs. Can it not be referenced by number still?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right, it should be the same.

column_target.alias = compiler.collection_name
else:
column_target.target.db_column = f"{parent_template}{parent_pos}"
column_target.target.set_attributes_from_name(f"{parent_template}{len(lhs_fields)}")
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to use len(lhs_fields) instead of parent_pos

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@WaVEV WaVEV force-pushed the add-support-join-extra-conditions branch 4 times, most recently from 5bc356b to ac054a7 Compare September 24, 2024 16:44
@WaVEV WaVEV force-pushed the add-support-join-extra-conditions branch from ac054a7 to e1042f5 Compare September 27, 2024 00:20
By adding support for Field.get_extra_restriction().
@timgraham timgraham force-pushed the add-support-join-extra-conditions branch from e52293a to 78a8619 Compare September 27, 2024 14:37
@timgraham timgraham changed the title Add support join extra conditions fix incorrect GenericRelation joining Sep 27, 2024
@timgraham timgraham merged commit 78a8619 into mongodb:main Sep 27, 2024
3 checks passed
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.

3 participants