Skip to content

Commit

Permalink
fix(core): ensure to have correct attribute id when a previous one ex…
Browse files Browse the repository at this point in the history
…isted (#1307)
  • Loading branch information
bobeal authored Jan 7, 2025
1 parent b9bca70 commit e88ba43
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class EntityAttributeService(
private val logger = LoggerFactory.getLogger(javaClass)

@Transactional
suspend fun create(attribute: Attribute): Either<APIException, Unit> =
suspend fun create(attribute: Attribute): Either<APIException, UUID> =
databaseClient.sql(
"""
INSERT INTO temporal_entity_attribute
Expand All @@ -110,6 +110,7 @@ class EntityAttributeService(
attribute_value_type = :attribute_value_type,
modified_at = :created_at,
payload = :payload
RETURNING id
""".trimIndent()
)
.bind("id", attribute.id)
Expand All @@ -120,7 +121,7 @@ class EntityAttributeService(
.bind("created_at", attribute.createdAt)
.bind("dataset_id", attribute.datasetId)
.bind("payload", attribute.payload)
.execute()
.oneToResult { row -> toUuid(row["id"]) }

@Transactional
suspend fun updateOnUpdate(
Expand Down Expand Up @@ -215,10 +216,10 @@ class EntityAttributeService(
createdAt = createdAt,
payload = Json.of(serializeObject(attributePayload))
)
create(attribute).bind()
val attributeUuid = create(attribute).bind()

val attributeInstance = AttributeInstance(
attributeUuid = attribute.id,
attributeUuid = attributeUuid,
timeProperty = AttributeInstance.TemporalProperty.CREATED_AT,
time = createdAt,
attributeMetadata = attributeMetadata,
Expand All @@ -229,7 +230,7 @@ class EntityAttributeService(

if (attributeMetadata.observedAt != null) {
val attributeObservedAtInstance = AttributeInstance(
attributeUuid = attribute.id,
attributeUuid = attributeUuid,
time = attributeMetadata.observedAt,
attributeMetadata = attributeMetadata,
payload = attributePayload
Expand Down

0 comments on commit e88ba43

Please sign in to comment.