Merged
Conversation
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
Comment on lines
+1360
to
+1363
| def save(self, *args, **kwargs): | ||
| if not self.issue_date: | ||
| self.issue_date = getattr(self, "created_on", None) | ||
| super().save(*args, **kwargs) |
There was a problem hiding this comment.
Bug: The save() method on BaseCertificate incorrectly sets issue_date to None for new objects, which will cause a database IntegrityError because the field is non-nullable.
Severity: HIGH
Suggested Fix
Modify the save() method to avoid setting issue_date to None. Instead of reading from created_on (which is None on new instances pre-save), the logic should be removed to allow the field's default=timezone.now to function correctly. Alternatively, check if the object is new (e.g., self.pk is None) and handle the logic accordingly without assigning None.
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: courses/models.py#L1360-L1363
Potential issue: When a new `BaseCertificate` instance is created without an
`issue_date` being explicitly set, the custom `save()` method is triggered. Inside this
method, the condition `if not self.issue_date:` evaluates to true. The code then
attempts to set `self.issue_date` from `self.created_on`. However, for a new object that
has not yet been saved to the database, `created_on` is `None`. This results in
`self.issue_date` being explicitly set to `None`, which overrides the field's
`default=timezone.now`. When `super().save()` is called, this `None` value violates the
`null=False` database constraint, causing an `IntegrityError` and preventing new
certificates from being created.
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.
annagav
renovate[bot]
Rachel Lougee
Tobias Macey