fix: Align connector entity client with API schema#43
Open
dmcnaught wants to merge 1 commit intopenguintechinc:mainfrom
Open
fix: Align connector entity client with API schema#43dmcnaught wants to merge 1 commit intopenguintechinc:mainfrom
dmcnaught wants to merge 1 commit intopenguintechinc:mainfrom
Conversation
The update_entity method was sending fields that aren't accepted by the API's UpdateEntityRequest schema (which uses extra='forbid'): - organization_id: Not updatable after creation - owner_identity_id: Not a valid update field This caused 400 Bad Request errors when the connector tried to update discovered AWS resources (VPCs, EC2, RDS, ElastiCache, SQS, Lambda). Only S3 buckets worked because they didn't trigger updates. Changes: - Remove organization_id from update_entity (not changeable) - Remove owner_identity_id from update_entity (not in schema) - Add sub_type to both create_entity and update_entity (supported by API) - Add documentation explaining the update constraints - Add sub_type to logging for better observability
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAligns the connector's entity creation and update payloads with the backend UpdateEntityRequest schema by adding support for sub_type and removing non-updatable fields that caused 400 errors. Sequence diagram for updated entity update flowsequenceDiagram
actor Connector
participant ElderClient
participant BackendAPI
Connector->>ElderClient: update_entity(entity_id, entity)
ElderClient->>ElderClient: Build UpdateEntityRequest payload
ElderClient->>BackendAPI: PATCH /entities/{entity_id}
activate BackendAPI
BackendAPI->>BackendAPI: Validate payload with UpdateEntityRequest
BackendAPI-->>ElderClient: 200 OK Updated entity
deactivate BackendAPI
ElderClient-->>Connector: Updated entity response
%% Payload fields after fix
rect rgb(235, 235, 235)
ElderClient->>BackendAPI: Payload
ElderClient-->>BackendAPI: name
ElderClient-->>BackendAPI: entity_type
ElderClient-->>BackendAPI: description
ElderClient-->>BackendAPI: sub_type
ElderClient-->>BackendAPI: parent_id
ElderClient-->>BackendAPI: attributes
ElderClient-->>BackendAPI: tags
ElderClient-->>BackendAPI: is_active
end
Class diagram for Entity and UpdateEntityRequest alignmentclassDiagram
class Entity {
+str name
+str entity_type
+str organization_id
+str description
+str sub_type
+int parent_id
+dict attributes
+list~str~ tags
+bool is_active
+str owner_identity_id
}
class UpdateEntityRequest {
+str name
+str description
+str entity_type
+str sub_type
+int parent_id
+dict attributes
+list~str~ tags
+dict default_metadata
+bool is_active
}
class ElderClient {
+create_entity(entity) Dict
+update_entity(entity_id, entity) Dict
}
ElderClient --> Entity : uses
ElderClient --> UpdateEntityRequest : maps_to
%% Highlight non_updatable and aligned fields
class Entity {
+str organization_id
+str owner_identity_id
}
Entity .. UpdateEntityRequest : aligned_fields
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- For both create_entity and update_entity, consider excluding keys whose values are None from the payload so that partial updates don't unintentionally overwrite existing fields with nulls (e.g., sub_type, description).
- Given that organization_id and owner_identity_id are no longer sent on update, it may be worth asserting or validating earlier in the flow that these fields are not expected to change, to catch any future misuse of the Entity model before making the API call.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- For both create_entity and update_entity, consider excluding keys whose values are None from the payload so that partial updates don't unintentionally overwrite existing fields with nulls (e.g., sub_type, description).
- Given that organization_id and owner_identity_id are no longer sent on update, it may be worth asserting or validating earlier in the flow that these fields are not expected to change, to catch any future misuse of the Entity model before making the API call.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
organization_idandowner_identity_idfromupdate_entityas they're not valid update fieldssub_typeto bothcreate_entityandupdate_entityto properly support entity sub-typesProblem
The connector's
update_entitymethod was sending fields that the API'sUpdateEntityRequestschema doesn't accept. SinceUpdateEntityRequestusesextra='forbid'(fromRequestModel), any extra fields cause immediate validation failures:organization_id: Not updatable after entity creation - entities are bound to their organizationowner_identity_id: Not defined in the UpdateEntityRequest schemaThis caused all AWS resource syncs (except S3 buckets) to fail with 400 errors when updating existing entities.
Root Cause
Test plan
sub_typeis properly set for entities that use it (RDS, ElastiCache, SQS, Lambda)Summary by Sourcery
Align connector entity create and update payloads with the API's UpdateEntityRequest schema to prevent validation errors when syncing entities.
Bug Fixes:
Enhancements: