-
Notifications
You must be signed in to change notification settings - Fork 76
fix: use datetime.fromisoformat() to handle timezone offsets in event… #1634
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -265,6 +265,40 @@ async def test_handle_events(ws_communicator: WebsocketCommunicator): | |
| assert (await get_job_instance_event_count()) == 1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "created_timestamp", | ||
| [ | ||
| pytest.param("2023-03-29T15:00:17.260803", id="naive"), | ||
| pytest.param("2023-03-29T15:00:17.260803Z", id="utc_z_suffix"), | ||
| pytest.param("2023-03-29T15:00:17.260803+00:00", id="utc_offset"), | ||
| pytest.param("2023-03-29T15:00:17.260803+05:30", id="positive_offset"), | ||
| pytest.param("2023-03-29T15:00:17.260803-04:00", id="negative_offset"), | ||
| ], | ||
|
ptoscano marked this conversation as resolved.
|
||
| ) | ||
| @pytest.mark.django_db(transaction=True) | ||
| async def test_handle_events_with_timezone_in_created( | ||
| ws_communicator: WebsocketCommunicator, | ||
| created_timestamp: str, | ||
| ): | ||
| job_instance = await _prepare_job_instance() | ||
|
|
||
| initial_count = await get_job_instance_event_count() | ||
| payload = { | ||
| "type": "AnsibleEvent", | ||
| "event": { | ||
| "event": "verbose", | ||
| "job_id": job_instance.uuid, | ||
| "counter": 1, | ||
| "stdout": "the playbook is completed", | ||
| "created": created_timestamp, | ||
| }, | ||
| } | ||
| await ws_communicator.send_json_to(payload) | ||
| await ws_communicator.wait() | ||
|
|
||
| assert (await get_job_instance_event_count()) == initial_count + 1 | ||
|
Comment on lines
+279
to
+299
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICS, this test only checks that the event is processed, however nothing actually seems to check that the wanted
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ptoscano This was a parsing error that I was trying to fix, there is another issue which relates to created_at should be set differently that requires DB migration. I think that should be done in a different PR. This was limited to fixing the parsing error.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That is a different problem, yes. What I'm saying is different: this test does not actually test that the result of the |
||
|
|
||
|
|
||
| @pytest.mark.django_db(transaction=True) | ||
| async def test_handle_actions_multiple_firing( | ||
| ws_communicator: WebsocketCommunicator, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
rg -n -C 3 'JobInstanceEvent|created_at\s*=' src/aap_eda/core/models/job.pyRepository: ansible/eda-server
Length of output: 757
Persist the WebSocket event timestamp in
JobInstanceEvent.created_at.JobInstanceEvent.created_atis defined withauto_now_add=True, so the parsedcreatedvalue passed intoJobInstanceEvent.objects.create(...)is overwritten by insertion time. Either make the field editable / add it to the serializer or omit it from the model if only the runtime event time should be kept.🤖 Prompt for AI Agents
Source: Path instructions