Skip to content

Conversation

JaeHyuckSa
Copy link
Contributor

@JaeHyuckSa JaeHyuckSa commented May 16, 2025

Trac ticket number

ticket-36389

Branch description

Fixed GenericRelation.update() to use write database connection instead of read connection in multi-database environments.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@RealOrangeOne
Copy link
Member

Whilst this fixes the case for .update, I think the issue would still happen with .delete (and other writing queryset APIs. I'd hope there's a more generic solution for this, rather than needing to override each method.

@JaeHyuckSa
Copy link
Contributor Author

JaeHyuckSa commented May 17, 2025

Hi @RealOrangeOne, Thanks for the review! I felt that applying the suggested approach would lead to more unnecessary changes, so I decided to go with a slightly different solution instead.

Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

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

Thank you @JaeHyuckSa
I also tested this against the test project in the ticket 👍

Comment on lines +614 to +615
queryset._defer_next_filter = True
return queryset.filter(**self.core_filters)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
queryset._defer_next_filter = True
return queryset.filter(**self.core_filters)
return queryset.filter(**self.core_filters)

I think I can remove _defer_next_filter without test failures

However, this is almost identical to ManyRelatedManager._apply_rel_filters except this would then be:

Suggested change
queryset._defer_next_filter = True
return queryset.filter(**self.core_filters)
queryset._defer_next_filter = True
return queryset._next_is_sticky().filter(**self.core_filters)

I am not sure what would be correct here but we can either simplify this or we should add more tests

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