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

[Framework] Fix bug search relation error unhashable dict #956

Merged
merged 10 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

<!-- towncrier release notes start -->

## 0.10.4 (2024-08-28)

### Bug Fixes

- Fixed upsert entity failure when saving modified data for search relations calculations


## 0.10.3 (2024-08-28)

### Bug Fixes
Expand All @@ -20,6 +27,7 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Reverted last bugfix


## 0.10.1 (2024-08-26)

### Bug Fixes
Expand Down
23 changes: 18 additions & 5 deletions port_ocean/clients/port/mixins/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,24 @@ async def upsert_entity(
)
handle_status_code(response, should_raise)
result = response.json()
result_entity = Entity.parse_obj(result)
# Set the results of the search relation and identifier to the entity
entity.identifier = result_entity.identifier or entity.identifier
entity.relations = result_entity.relations or entity.relations
return entity
result_entity = (
Entity.parse_obj(result["entity"]) if result.get("entity") else entity
Comment on lines +61 to +62
Copy link
Contributor

Choose a reason for hiding this comment

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

returning all the result entity means that we return the full entity that is inside port, this means that if we just ingested the relations of an entity but it has 20 more properties it will be returned here and passed forward to the resync phase. This can be problematic from a memory point of view and that is why we only took the identifier and the relations from the result entity and not the full entity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need the blueprint as well to delete the identifier of a specific blueprint only as there may be entities with same identifier but different blueprints

)
# In order to save memory we'll keep only the identifier, blueprint and relations of the
# upserted entity result for later calculations
reduced_entity = Entity(
identifier=result_entity.identifier, blueprint=result_entity.blueprint
)

# Turning dict typed relations (raw search relations) is required
# for us to be able to successfully calculate the participation related entities
# and ignore the ones that don't as they weren't upserted
reduced_entity.relations = {
key: None if isinstance(relation, dict) else relation
for key, relation in result_entity.relations.items()
}

return reduced_entity

async def batch_upsert_entities(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.10.3"
version = "0.10.4"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down