forked from platypush/platypush
Explictly cast entity IDs to strings when coalescing entity updates
Some plugins may represent entity IDs as integers, while the database maps external IDs to strings. This may result in entities being incorrectly mapped during merging. Casting to string prevents these type-related ambiguities.
This commit is contained in:
parent
975991ba69
commit
f45df5d4d3
1 changed files with 15 additions and 4 deletions
|
@ -172,7 +172,12 @@ class EntitiesEngine(Thread):
|
|||
self, session: Session, entities: Iterable[Entity]
|
||||
) -> Iterable[Entity]:
|
||||
existing_entities = {
|
||||
(entity.external_id or entity.name, entity.plugin): entity
|
||||
(
|
||||
str(entity.external_id)
|
||||
if entity.external_id is not None
|
||||
else entity.name,
|
||||
entity.plugin,
|
||||
): entity
|
||||
for entity in session.query(Entity)
|
||||
.filter(
|
||||
or_(
|
||||
|
@ -194,7 +199,13 @@ class EntitiesEngine(Thread):
|
|||
|
||||
return [
|
||||
existing_entities.get(
|
||||
(entity.external_id or entity.name, entity.plugin), None
|
||||
(
|
||||
str(entity.external_id)
|
||||
if entity.external_id is not None
|
||||
else entity.name,
|
||||
entity.plugin,
|
||||
),
|
||||
None,
|
||||
)
|
||||
for entity in entities
|
||||
]
|
||||
|
@ -207,8 +218,8 @@ class EntitiesEngine(Thread):
|
|||
for col in columns:
|
||||
if col == 'meta':
|
||||
existing_entity.meta = { # type: ignore
|
||||
**(existing_entity.meta or {}),
|
||||
**(entity.meta or {}),
|
||||
**(existing_entity.meta or {}), # type: ignore
|
||||
**(entity.meta or {}), # type: ignore
|
||||
}
|
||||
elif col not in ('id', 'created_at'):
|
||||
setattr(existing_entity, col, getattr(entity, col))
|
||||
|
|
Loading…
Reference in a new issue