Closed
Conversation
OpenAPI ChangesShow/hide 412 changes: 30 error, 21 warning, 361 info |
Comment on lines
+37
to
+42
| migrations.AlterUniqueTogether( | ||
| name="contentfile", | ||
| unique_together={ | ||
| ("key", "run", "learning_resource", "direct_learning_resource") | ||
| }, | ||
| ), |
There was a problem hiding this comment.
Bug: The query ContentFile.objects.filter(key=s3_path).first() in the OCW loader is now ambiguous due to a change in unique constraints, potentially fetching an incorrect record.
Severity: MEDIUM
Suggested Fix
Update the query in the get_file_content function within learning_resources/etl/ocw.py to be more specific. The filter should include the run or direct_learning_resource in addition to the key to ensure the correct ContentFile object is retrieved, preventing ambiguity.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: learning_resources/migrations/0103_contentfilechanges.py#L37-L42
Potential issue: A change in the unique constraints for the `ContentFile` model allows
for duplicate `key` values across different parent objects (e.g., different `run`s).
However, the OCW ETL process in `get_file_content` queries for existing files using
`ContentFile.objects.filter(key=s3_path).first()`. This query only filters by `key` and
becomes ambiguous, potentially retrieving the wrong record if multiple `ContentFile`
objects share the same `key`. This can lead to incorrect reprocessing decisions based on
the wrong record's `updated_on` timestamp, causing files to be skipped or reprocessed
unnecessarily.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Anastasia Beglova