[DRAFT] FIX Surface AttackResultEntry.timestamp on hydrated AttackResult#1653
Open
thirteeneight wants to merge 2 commits intomicrosoft:mainfrom
Open
[DRAFT] FIX Surface AttackResultEntry.timestamp on hydrated AttackResult#1653thirteeneight wants to merge 2 commits intomicrosoft:mainfrom
thirteeneight wants to merge 2 commits intomicrosoft:mainfrom
Conversation
AttackResultEntry stores a non-nullable timestamp column, but get_attack_result() dropped it when rebuilding the AttackResult. The backend mapper then fell back to datetime.now() in attack_result_to_summary, so the UI showed today's date on every row no matter when it was actually persisted. Adds an optional timestamp field to AttackResult, passes it through _ensure_utc() in get_attack_result(), and has attack_result_to_summary prefer ar.timestamp over datetime.now() when metadata["created_at"] is absent. The metadata override path is unchanged, and callers that do not set the new field get None (same behavior as before). Fixes microsoft#1651
Author
|
@microsoft-github-policy-service agree |
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.
Description
Fixes #1651.
AttackResultEntrypersists a non-nullabletimestampcolumn, butget_attack_result()dropped it when rebuilding the domainAttackResult. The backend mapper'sattack_result_to_summarythen fell back todatetime.now(timezone.utc), so the UI showed today's date on every row no matter when it was actually persisted.Three small, additive changes:
timestamp: Optional[datetime] = Nonefield to theAttackResultdataclass.timestamp=_ensure_utc(self.timestamp)inAttackResultEntry.get_attack_result().attack_result_to_summary, preferar.timestampoverdatetime.now()whenmetadata["created_at"]is absent. The metadata override path is preserved unchanged.Backwards compatible:
AttackResultEntries.timestamphas been non-nullable since the entry was introduced, so every existing row has a value to hydrate from. Callers constructing anAttackResultwithout the new field getNone, which the mapper treats the same as missing metadata.Filed as draft pending maintainer feedback on #1651.
Tests and Documentation
New unit tests:
tests/unit/models/test_attack_result.py::TestAttackResultTimestamp— default isNone, aware datetime is preserved, round-trip throughAttackResultEntry, naive SQLite timestamps are normalized to UTC on hydration.tests/unit/backend/test_mappers.py::TestAttackResultToSummary— three new cases coveringar.timestamppreferred when metadata is absent, metadata still wins when both are present, fallback todatetime.now()when both are absent.Verification:
pytest tests/unit/— 1339 passed, 0 regressions.mypy --stricton the three modified source files — clean.ruff formatandruff check— clean.