Giter VIP home page Giter VIP logo

Comments (3)

Sascha6790 avatar Sascha6790 commented on June 26, 2024 1

I see, that's unfortunate but you still helped me a lot, thank you.

Patching typeorm with npx patch-package works for now as a temporarily solution
Maybe it's possible to make relationLoadStrategy configurable for now but actually should be solved on typeorms end

Leaving the patch here:

diff --git a/node_modules/typeorm/browser/query-builder/SelectQueryBuilder.js b/node_modules/typeorm/browser/query-builder/SelectQueryBuilder.js
index c78a50f..c4e90e6 100644
--- a/node_modules/typeorm/browser/query-builder/SelectQueryBuilder.js
+++ b/node_modules/typeorm/browser/query-builder/SelectQueryBuilder.js
@@ -2052,7 +2052,12 @@ export class SelectQueryBuilder extends QueryBuilder {
             const queryStrategyRelationIdLoader = new QueryStrategyRelationIdLoader(this.connection, queryRunner);
             await Promise.all(this.relationMetadatas.map(async (relation) => {
                 const relationTarget = relation.inverseEntityMetadata.target;
-                const relationAlias = relation.inverseEntityMetadata.targetName;
+                const relationAlias = this.connection.namingStrategy.joinTableName(
+                  relation.propertyName,
+                  relation.inverseEntityMetadata.name,
+                  relation.propertyName,
+                  relation.inverseSidePropertyPath,
+                );
                 const select = Array.isArray(this.findOptions.select)
                     ? OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
                     : this.findOptions.select;
diff --git a/node_modules/typeorm/query-builder/SelectQueryBuilder.js b/node_modules/typeorm/query-builder/SelectQueryBuilder.js
index 8eda00e..fdf7e7c 100644
--- a/node_modules/typeorm/query-builder/SelectQueryBuilder.js
+++ b/node_modules/typeorm/query-builder/SelectQueryBuilder.js
@@ -2055,7 +2055,11 @@ class SelectQueryBuilder extends QueryBuilder_1.QueryBuilder {
             const queryStrategyRelationIdLoader = new RelationIdLoader_2.RelationIdLoader(this.connection, queryRunner);
             await Promise.all(this.relationMetadatas.map(async (relation) => {
                 const relationTarget = relation.inverseEntityMetadata.target;
-                const relationAlias = relation.inverseEntityMetadata.targetName;
+                const relationAlias =  this.connection.namingStrategy.joinTableName(
+                  relation.propertyName,
+                  relation.propertyName,
+                  relation.inverseSidePropertyPath,
+                )
                 const select = Array.isArray(this.findOptions.select)
                     ? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
                     : this.findOptions.select;

File: typeorm+0.3.20.patch

from vendure.

michaelbromley avatar michaelbromley commented on June 26, 2024

Thanks for the report. I'm looking into this, and it appears it may well be a bug inside TypeORM. I have defined the "poster" custom field and when I attempt to load a product detail in the Admin UI, I get the reported error. Debugging through all the generated SQL queries generated by this request, I get to the specific one that fails:

SELECT `Asset`.`createdAt`                                    AS `Asset_createdAt`,
       `Asset`.`updatedAt`                                    AS `Asset_updatedAt`,
       `Asset`.`name`                                         AS `Asset_name`,
       `Asset`.`type`                                         AS `Asset_type`,
       `Asset`.`mimeType`                                     AS `Asset_mimeType`,
       `Asset`.`width`                                        AS `Asset_width`,
       `Asset`.`height`                                       AS `Asset_height`,
       `Asset`.`fileSize`                                     AS `Asset_fileSize`,
       `Asset`.`source`                                       AS `Asset_source`,
       `Asset`.`preview`                                      AS `Asset_preview`,
       `Asset`.`focalPoint`                                   AS `Asset_focalPoint`,
       `Asset`.`id`                                           AS `Asset_id`,
       `Asset`.`customFieldsPosterid`                         AS `Asset_customFieldsPosterid`,
       `Asset`.`customFields__fix_relational_custom_fields__` AS `Asset_customFields__fix_relational_custom_fields__`,
       `Asset`.`createdAt`                                    AS `Asset_createdAt`,
       `Asset`.`updatedAt`                                    AS `Asset_updatedAt`,
       `Asset`.`name`                                         AS `Asset_name`,
       `Asset`.`type`                                         AS `Asset_type`,
       `Asset`.`mimeType`                                     AS `Asset_mimeType`,
       `Asset`.`width`                                        AS `Asset_width`,
       `Asset`.`height`                                       AS `Asset_height`,
       `Asset`.`fileSize`                                     AS `Asset_fileSize`,
       `Asset`.`source`                                       AS `Asset_source`,
       `Asset`.`preview`                                      AS `Asset_preview`,
       `Asset`.`focalPoint`                                   AS `Asset_focalPoint`,
       `Asset`.`id`                                           AS `Asset_id`,
       `Asset`.`customFieldsPosterid`                         AS `Asset_customFieldsPosterid`,
       `Asset`.`customFields__fix_relational_custom_fields__` AS `Asset_customFields__fix_relational_custom_fields__`
FROM `asset` `Asset`
         INNER JOIN `asset` `Asset` ON `Asset`.`customFieldsPosterid` = `Asset`.`id`
WHERE `Asset`.`id` IN (?)

with the following stack trace:

image

I'm investigating whether there is any kind of work-around we can perform on our side.

from vendure.

michaelbromley avatar michaelbromley commented on June 26, 2024

Given the following custom field config:

 customFields: {
        Asset: [
            {
                type: 'relation',
                entity: Asset,
                name: 'self',
                nullable: true,
            },
        ],
    },

here's a minimal query to the Admin or Shop API which reproduces the error:

{
  product(id: 1) {
    featuredAsset {
      customFields {
        self {
          id
        }
      }
    }
  }
}

Interestingly, running the same query against collection will not produce the error. This may be due to the fact that there is currently a work-around which causes the collection query to opt-out of the relationLoadStrategy: 'query' strategy of TypeORM.

This is supported by the fact that if I comment out this line, the error will not appear.

So we can narrow this down to the internal implementation in TypeORM of the "query" relationLoadStrategy - something that has proven a source of bugs in the past. Which is very unfortunate because it brings huge performance improvements overall.

On further investigation I believe we are running into exactly this bug:

from vendure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.