diff --git a/.changeset/early-spies-grow.md b/.changeset/early-spies-grow.md new file mode 100644 index 0000000000..3591b1398a --- /dev/null +++ b/.changeset/early-spies-grow.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': patch +--- + +Fixed a bug where the catalog would read back all entities when adding a location that already exists. diff --git a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts index 7ba6897236..76fc63c9b3 100644 --- a/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts +++ b/plugins/catalog-backend/src/catalog/DatabaseEntitiesCatalog.ts @@ -205,7 +205,7 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { } } - if (options?.outputEntities) { + if (options?.outputEntities && responses.length > 0) { const writtenEntities = await this.database.entities( tx, EntityFilters.ofMatchers({ @@ -285,7 +285,8 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog { // instead and call a dedicated batch update database method toUpdate.push(request); } else { - toIgnore.push(request); + // Use the existing entity to ensure that we're able to read it back by uid if needed + toIgnore.push({ ...request, entity: oldEntity }); } }