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

Fix datetime user data #33818

Merged
merged 1 commit into from
Nov 30, 2023
Merged

Fix datetime user data #33818

merged 1 commit into from
Nov 30, 2023

Conversation

esoergel
Copy link
Contributor

@esoergel esoergel commented Nov 30, 2023

Product Description

Fixes a bug where the thing that copies user data to SQL choked on data that looked like a datetime stamp, causing 500s

Technical Summary

https://dimagi-dev.atlassian.net/browse/SUPPORT-18199

Introduced in #33688

If user data contains a datetime string, jsonobject parses it into a date object, which we can't send directly to a SQL json field. To address this, I use the json-compatible version of the user object and extract the user_data from that, using jsonobject's serialization.

A side effect of this change is that I cannot pass the object by reference, meaning updates to it are not passed back to couch. I think this is actually an improvement, as the prior behavior was inconsistent anyways (it'd only pass back when first initialized, and not thereafter).

Feature Flag

Safety Assurance

Safety story

Local testing, will deploy to staging first.

Automated test coverage

included

QA Plan

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

If user data contains a datetime string, jsonobject parses it into a
date object, which we can't send directly to a SQL json field.  To
address this, I use the json-compatible version of the user object and
extract the user_data from that, using jsonobject's serialization.

A side effect of this change is that I cannot pass the object by
reference, meaning updates to it are not passed back to couch.  I think
this is actually an improvement, as the prior behavior was inconsistent
anyways (it'd only pass back when first initialized, and not
thereafter).
@esoergel esoergel added the product/all-users-all-environments Change impacts all users on all environments label Nov 30, 2023
@dimagimon dimagimon added the Risk: High Change affects files that have been flagged as high risk. label Nov 30, 2023
Copy link
Contributor

@gherceg gherceg left a comment

Choose a reason for hiding this comment

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

Feel free to ignore the nit given the circumstances of this PR (having to wait for test build, etc).

Comment on lines +41 to +42
# Normally you shouldn't use `user.user_data` directly - I'm demonstrating that it's not updated
self.assertEqual(user.user_data, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this test could be renamed to test_couch_user_data_does_not_update or something like that right? Partially asking to make sure I understand this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's correct - I think I named it this because it was the first basic test using the accessor. I'll clean it up in the followup PR once the migration is fully rolled out

@esoergel esoergel marked this pull request as ready for review November 30, 2023 16:47
@esoergel esoergel merged commit 1b67098 into master Nov 30, 2023
13 checks passed
@esoergel esoergel deleted the es/user-data-fix branch November 30, 2023 17:04
@esoergel esoergel mentioned this pull request Nov 30, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product/all-users-all-environments Change impacts all users on all environments Risk: High Change affects files that have been flagged as high risk.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants