Skip to content
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

Add check for dict in serialize function #48

Conversation

OhmniD
Copy link
Contributor

@OhmniD OhmniD commented Jul 26, 2024

Description:

This pull request introduces a change to the serialize function in smartsheet/util.py to ensure that the additionalDetails property is correctly serialized when present in the response for the Event Reporting API.

Changes:

  1. Code Changes:

    • Added an elif isinstance(obj, dict) statement in the serialize function to handle dictionary objects. This ensures that properties like additionalDetails, which are dictionaries with an unknown number/type of key:value pairs, are correctly serialized and included in the output.
  2. Test Changes:

    • Updated the integration test test_list_events in tests/integration/test_events.py to include a check for the additionalDetails field. This test now verifies that when additionalDetails is present, it is correctly populated and is of type dict.

Reason for Change:

The additionalDetails property was missing when querying Event Reporting. By adding the elif isinstance(obj, dict) statement, we ensure that dictionary properties are handled properly during the serialization process, preserving the integrity of the API response.

Testing:

  • Ran a small script to query the Event Reporting API and verify that the additionalDetails field is correctly serialized and populated when present in the response (sample outputs below).
  • Ran all mock and integration tests locally
    • Before this change the test results were: 8 failed, 340 passed, 10 skipped, 1 xpassed, 89 warnings, 16 rerun
    • After this change (and adding the additional test), the test results were identical - none of the failures appear to be related to Event Reporting or serialization
    • It should be noted that a number of the serialization mock tests were skipped due to the mock API not being updated, and also there doesn't appear to be any mock tests for Events.

Sample output:

Without handling dicts during serialization:

{
    "action": "AUTHORIZE",
    "additionalDetails": {},
    "eventId": "REDACTED",
    "eventTimestamp": "2024-03-20T16:03:17+00:00Z",
    "objectId": "REDACTED",
    "objectType": "ACCESS_TOKEN",
    "requestUserId": "REDACTED",
    "source": "UNKNOWN",
    "userId": "REDACTED"
}

With change to serialize dicts:

{
    "action": "AUTHORIZE",
    "additionalDetails": {
        "tokenExpirationTimestamp": "2024-03-27T16:03:17Z",
        "emailAddress": "REDACTED",
        "firstLoginTimestamp": "2018-09-18T20:07:03Z",
        "appName": "REDACTED",
        "accessScopes": "ADMIN_USERS,CREATE_SHEETS,ADMIN_WEBHOOKS,READ_USERS,WRITE_SHEETS,ADMIN_SHEETS,READ_SHEETS",
        "tokenDisplayValue": "REDACTED",
        "appClientId": "REDACTED"
    },
    "eventId": "REDACTED",
    "eventTimestamp": "2024-03-20T16:03:17+00:00Z",
    "objectId": "REDACTED",
    "objectType": "ACCESS_TOKEN",
    "requestUserId": "REDACTED",
    "source": "UNKNOWN",
    "userId": "REDACTED"
}

** Note: **
I believe this supersedes Salman's PR here - additionalDetails is still empty when querying when I tested with his change.

@OhmniD OhmniD marked this pull request as ready for review July 26, 2024 16:07
Copy link

@an-shaik an-shaik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@an-shaik
Copy link

@dmurray-smar : Pipeline seem to be failing. Can you please have a look?

@fleighton fleighton merged commit 4128242 into smartsheet:mainline Jul 30, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants