Skip to content

Commit

Permalink
fix: ignore inconsistent foreign key types (#1202)
Browse files Browse the repository at this point in the history
* fix: ignore inconsistent fk types

* refactor: function is static

* refactor: naming

---------

Co-authored-by: Nicolas Moreau <nicolas.moreau76@gmail.com>
  • Loading branch information
realSpok and Nicolas Moreau authored Nov 5, 2024
1 parent 6168792 commit b5e8c6a
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ export default class RelationCollectionDecorator extends CollectionDecorator {
await Promise.all(promises);
}

// in the case of https://app.clickup.com/t/86c0vvu15
// an external datasource with inconsistent column type
// fk could be NaN, which crashes the agent
private static isKeyApplicable = key => {
return key !== null && !Number.isNaN(key);
};

private async reprojectRelationInPlace(
caller: Caller,
records: RecordData[],
Expand All @@ -308,7 +315,10 @@ export default class RelationCollectionDecorator extends CollectionDecorator {
projection,
);
} else if (schema.type === 'ManyToOne') {
const ids = records.map(record => record[schema.foreignKey]).filter(fk => fk !== null);
const ids = records
.map(record => record[schema.foreignKey])
.filter(RelationCollectionDecorator.isKeyApplicable);

const subFilter = new Filter({
conditionTree: new ConditionTreeLeaf(schema.foreignKeyTarget, 'In', [...new Set(ids)]),
});
Expand All @@ -324,7 +334,9 @@ export default class RelationCollectionDecorator extends CollectionDecorator {
);
}
} else if (schema.type === 'OneToOne' || schema.type === 'OneToMany') {
const ids = records.map(record => record[schema.originKeyTarget]).filter(okt => okt !== null);
const ids = records
.map(record => record[schema.originKeyTarget])
.filter(RelationCollectionDecorator.isKeyApplicable);
const subFilter = new Filter({
conditionTree: new ConditionTreeLeaf(schema.originKey, 'In', [...new Set(ids)]),
});
Expand Down

0 comments on commit b5e8c6a

Please sign in to comment.