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

Data contains dictionary if value is empty #166

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

iLLiCiTiT
Copy link
Member

Description

Use empty dictionary when "data" value is None.

Additional information

When data are empty on entity server does return None instead of "{}", added functionality makes None value as dictionary.

Comment on lines 8137 to 8142
if not entity or "data" not in entity:
return
entity_data = entity.get("data")
if (
entity_data is not None
and isinstance(entity_data, str)
):
entity["data"] = json.loads(entity_data)

entity_data = entity["data"]
if entity_data is None:
entity_data = {}
Copy link

Choose a reason for hiding this comment

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

Isn't this quite similar as to just doing entity_data = entity.get("data") or {}

Copy link
Member Author

Choose a reason for hiding this comment

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

"data" should not be filled if are not available in entity.

Copy link

Choose a reason for hiding this comment

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

I see - we may want to update the PR description then to explain that with this PR it entity will also lack "data" completely whereas previously it may have been None. The PR isn't necessarily enforcing data to be dict but only enforcing that it will be - if it was existing in in the input data.

Copy link

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

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

Didn't test but code looks good to me.

I did want to point out the comment made here that the PR may do more than the PR description describes currently.

Also, not sure how to really test this? As in, when is data empty on the server? :)

@iLLiCiTiT iLLiCiTiT changed the title Data is always dictionary Data contains dictionary if value is empty Aug 2, 2024
@iLLiCiTiT
Copy link
Member Author

As in, when is data empty on the server? :)

All new entities that don't have anything in "data" :)

@iLLiCiTiT iLLiCiTiT merged commit 2eaf97c into develop Aug 2, 2024
@iLLiCiTiT iLLiCiTiT deleted the enhancement/data-is-always-dictionary branch August 2, 2024 13:10
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