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

Fix populate_diff_id_fields management command #1580

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

lucasmarchd01
Copy link
Contributor

@lucasmarchd01 lucasmarchd01 commented Aug 6, 2024

This management command fixes #1368 where some chants have non-empty differentiae_database fields but empty diff_db fields. It iterates through these chants, attempts to find the corresponding Differentia object based on the differentiae_database value, and assigns it to the diff_db field. If the Differentia object does not exist, it creates a new Differentia with the given ID, saves it, and then assigns it to the diff_db field of the chant.

Previously, we encountered an issue with the populate_diff_id_fields management command where only some of the affected chants are updated. Here are the fixes:

  • The @transaction.atomic decorator is applied to the handle method to ensure that the entire process runs within a single database transaction. This means either all changes are committed, or none are, which maintains database consistency in case of errors.
  • Uses .iterator(chunk_size=500) to process chants in chunks directly from the database, which is more memory-efficient and reduces the risk of memory overload.
  • Moves the creation of a new Differentia to the except block since the else block was obsolete. The get method will return the object if found or an exception.

I've run this command locally and it works as expected.

@lucasmarchd01 lucasmarchd01 requested a review from dchiller August 6, 2024 16:52
@lucasmarchd01 lucasmarchd01 merged commit f0e5ce6 into DDMAL:develop Aug 7, 2024
1 check 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.

Some chants with non-empty differentiae_database fields have empty diff_id fields
2 participants