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

[SYNPY-1453] Guard around modified time item in cache #1080

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

BryanFauble
Copy link
Contributor

Problem:

  1. In the cache if a cache value was a dictionary but it did not contain the exact key of modified_time the code would return back the parent dict - causing further code to fail that was expecting a string to be returned.

Solution:

  1. Adding a guard statement in _get_cache_modified_time that verified that the data returned is going to be a string or the value for modified_time

Testing:

Added unit tests around the logic that verify the behavior if the cache map:

  1. Is a dict but does not contain modified_time key
  2. Is a dict but contains neither of the expected keys
  3. The entry is an empty dict
  4. The entry is None

@BryanFauble BryanFauble requested a review from a team as a code owner April 2, 2024 23:24
Copy link

sonarcloud bot commented Apr 3, 2024

Copy link
Member

@thomasyu888 thomasyu888 left a comment

Choose a reason for hiding this comment

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

Thanks for the quick bug fix, just a comment

@@ -161,8 +164,9 @@ def _get_cache_modified_time(
"""
if cache_map_entry is not None and "modified_time" in cache_map_entry:
return cache_map_entry.get("modified_time", None)
else:
elif cache_map_entry is not None and isinstance(cache_map_entry, str):
Copy link
Member

Choose a reason for hiding this comment

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

I understand how this scenario occurs, but I'm confused as to how the cache map would get into that state. I know the old cache map looked something like this, but I thought we had tested downloading files between different cache map states.

{"/Users/tyu/.synapseCache/115/134016115/SYNAPSE_TABLE_QUERY_134016115.csv": "2024-03-07T06:29:19.000Z"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I look around the old and new code and I couldn't really find an explanation. The only case I'm thinking is if the cache map entry looked like:

{"/Users/tyu/.synapseCache/115/134016115/SYNAPSE_TABLE_QUERY_134016115.csv": {}}

or

{"/Users/tyu/.synapseCache/115/134016115/SYNAPSE_TABLE_QUERY_134016115.csv": {"someOtherValue": 123}}

I compared the previous code from 3.1.0 to the code in the file now and I do not see anywhere we are intentionally setting the value to an empty dict, or a dict that does not contain the expected keys.

As for testing I had verified that going forward on client versions handled this gracefully.

Copy link
Member

@thomasyu888 thomasyu888 left a comment

Choose a reason for hiding this comment

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

🔥 LGTM!

@BryanFauble BryanFauble merged commit e6c6959 into develop Apr 3, 2024
38 checks passed
@BryanFauble BryanFauble deleted the SYNPY-1453-add-check-around-cache-map-entry branch April 3, 2024 19:00
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.

None yet

2 participants