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

[IO-1626][external] Client fails when data structure is unexpected #655

Merged
merged 4 commits into from
Aug 31, 2023

Conversation

owencjones
Copy link
Contributor

Problem

On occasion, the API returns a nullish response instead of 0 for a zero count item, image or video count, which causes a crash

Solution

Have written a single function that calculates the item count for each dataset, based on appropriate elimination logic

Changelog

New function to calculate item counts, applied to all creations of RemoteDatasetV1 and RemoteDatasetV2 items.
Tests for new function
Tests to ensure that client and new function behave correctly together
Some cleanup of old typing and linting

@linear
Copy link

linear bot commented Aug 30, 2023

IO-1626 BUG: bug with adding different datatypes in client.py, specifically create_dataset(), list_remote_datasets(), & get_remote_dataset()

BUG submission from: John Wilkie
Summary (describe an issue):
Minor bug with adding different datatypes in client.py, specifically create_dataset(), list_remote_datasets(), & get_remote_dataset()

The use of dataset.get("{dict_key}", 0) means that sometimes None is returned, throwing a TypeError because we try to add NoneType to integers. It would be better to replace these gets with:
dataset.get("{dict_key}") or 0, so that if null is returned we take 0 instead

This is having a minor impact on one client at the moment. We have not been able to reproduce this yet, even on the client'd affected dataset. However, introducing better tolerance for this will prevent any further cases
Share Loom/Screenshots with Console/Network opened:
N/A
Darwin affected version
V2
Environment (production/staging; browser and OS version)

Impact
All (all Darwin users are impacted)
Priority
Low - little-to-no impact on users and can be fixed at any time
Steps to reproduce

Expected Behaviour

Team & Dataset Link
Team = https://darwin.v7labs.com/super_admin/teams/2235
Dataset = https://darwin.v7labs.com/datasets/675509/dataset-management/
Intercom ticket

Customer Name

Renewal timeline

ARR

Tier

Assigned CSM

self.session.mount("https://", adapter)

if log is None:
self.log: Logger = logging.getLogger("darwin")
else:
self.log = log

@staticmethod
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the biggest part of the change - most other changes are just code cleanup

@@ -5,19 +5,20 @@
import zlib
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are many changes in here which are just formatting or typing

  • Any -> UnknownType are equivalent, but one doesn't cause issues with linter.
  • Reformatting of lines has occurred in several unrelated places.

Only the implementation of the _get_item_count and its' use and testing are relevant to the fix

@@ -73,11 +74,53 @@ def test_returns_list_of_datasets(self, darwin_client: Client):
assert_dataset(remote_datasets[0], expected_dataset_1)
assert_dataset(remote_datasets[1], expected_dataset_2)

@responses.activate
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a socialised test, testing that the client is using the _get_item_count function correctly.

There is a functional unit test as well, testing the function in a pure functional way.

Copy link
Collaborator

@simedw simedw left a comment

Choose a reason for hiding this comment

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

overall LGTM

normally I don't try to test _ methods directly but I think it's fine.
Also _get_item_count doesn't really belong as a class method on Client, it's more of a utility function thing or could even live inside the RemoteDataset class?

@owencjones owencjones merged commit 3cc2d52 into master Aug 31, 2023
9 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.

2 participants