Fix User Credential Issued Date#266
Conversation
Record when a credential is issued to a user. auto_now_add stamps each new grant at insert time; existing rows are backfilled with the migration-run time. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The endpoint reported Credential.created_at (when the credential definition was created) as the date. Users expect the date the credential was issued to them. Serialize the user's grants directly (UserCredentialSerializer) via select_related, sourcing the definition fields from the related Credential and using the grant's own created_at for the date. This also removes the issuer N+1 the old per-Credential serialization incurred. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
WalkthroughAdds Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
users/tests/test_views.py (1)
605-623: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winAdd
@skip_app_integrity_checkto this endpoint test.This test goes through
auth_device.get(self.url), so it should bypass Play Integrity and fail only on the credential-list behavior under test.As per coding guidelines,
**/tests/*.py: Use@skip_app_integrity_checkdecorator in tests to bypass Google Play Integrity validation, and**/views.py: All app requests must validate Google Play Integrity tokens. Based on learnings, apply it only to individual HTTP tests, not the class.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@users/tests/test_views.py` around lines 605 - 623, Add the skip_app_integrity_check decorator to this endpoint test so auth_device.get(self.url) bypasses Play Integrity and the assertion focuses only on credential-list behavior. Update the test method test_success in the view tests to use the decorator on this individual HTTP test, not the class, keeping the rest of the setup and assertions unchanged.Sources: Coding guidelines, Learnings
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@users/migrations/0032_usercredential_created_at.py`:
- Around line 17-21: The migration for adding created_at to UserCredential
currently assigns one execution-time timestamp to all existing rows, so update
the release to include the historical backfill migration that populates real
created_at values before exposing them in ListCredentials, or gate the API
serialization until that backfill is shipped. Use the UserCredential migration
that adds created_at and the ListCredentials endpoint serialization path as the
key places to coordinate this change.
---
Outside diff comments:
In `@users/tests/test_views.py`:
- Around line 605-623: Add the skip_app_integrity_check decorator to this
endpoint test so auth_device.get(self.url) bypasses Play Integrity and the
assertion focuses only on credential-list behavior. Update the test method
test_success in the view tests to use the decorator on this individual HTTP
test, not the class, keeping the rest of the setup and assertions unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: aa7de27f-27b3-4d6f-b91c-a94a786ee415
📒 Files selected for processing (5)
users/migrations/0032_usercredential_created_at.pyusers/models.pyusers/serializers.pyusers/tests/test_views.pyusers/views.py
Technical Summary
Link to ticket here
This is a release path 1 feature — Improvements to existing features & quick wins.
The credential issue date returned by
ListCredentialspreviously came fromCredential.created_at, which is shared across every holder and environment of a credential and therefore does not reflect when an individual user was issued it. This PR adds a per-usercreated_attoUserCredentialand reworks the endpoint to serializeUserCredentialrows directly (pulling credential metadata through the relation), sodatenow reflects the actual per-user issuance time.Because
created_atwas added withauto_now_add, existing rows carry the migration run time rather than the true issuance date, so a management command will be added in a separate PR to backfillcreated_atfrom a JSON export of Connect prod'sUserCredential.issued_on.Logging and monitoring
No additional logging was added.
Safety Assurance
Safety story
The API change is read-only and additive — it adds a non-nullable field with a default and returns an additional, more accurate
datevalue. A separate PR will be addressing the data change to thecreated_atfield to sync it with theUserCredential.issued_ondate from Connect.Automated test coverage
Tests cover the
ListCredentialsresponse now sourcingdatefrom the per-userUserCredentialrecord.QA Plan
No QA planned for this change.
Labels & Review