Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeORM 0.2.20 getRepository returns results from another Repo. #4958

Closed
mabintact opened this issue Oct 23, 2019 · 6 comments
Closed

TypeORM 0.2.20 getRepository returns results from another Repo. #4958

mabintact opened this issue Oct 23, 2019 · 6 comments

Comments

@mabintact
Copy link

mabintact commented Oct 23, 2019

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.20

Steps to reproduce or a small repository showing the problem:

As soon as I update to TypeORM 0.2.20 (NPM Version) when we ran a graphql query the results obtain had nulls everywhere except for the keys. I added a console log to the query and discovered the results were for another repository NOT included in the query's file.

async getQuerySomething(_root: any, _args: any) {
const queryData = await getConnection("mainConn")
.getRepository(Repo)
.find();

console.log("/** getQuerySomething * Start ");
console.log(queryData);
console.log("
getQuerySomething * End **/");

return queryData;
},

The output of queryData showed results that were inconsistent with the repository. When outputing the result of getRepository, we could clearly see the table name was wrong. It wasn't even an Entity included in the Resolver file. The Entity came from another Resolver.

Reproducing the issue was easy as all we had to do was go back and forth from 0.2.19 to 0.2.20.
0.2.20 is the only version that seemed to cause the issue.

@pleerock
Copy link
Member

can you check if its the same issue as #4940 ?

@mabintact
Copy link
Author

The class names are different in our case.

One is:
@entity("request_type", {schema: "public" } )
export class RequestType {...}

and the other:
@entity("request_status", {schema: "public" } )
export class RequestStatus {...}

@smallg
Copy link

smallg commented Nov 18, 2019

@mabintact also catch this issue, how about solution?

@Soinou
Copy link

Soinou commented Dec 2, 2019

We are also encountering this issue. Here's what happens:

first.ts

import { Column, Entity } from "typeorm";

@Entity({ name: "first" })
export class First {
    @Column("int", {
        nullable: false,
        primary: true,
        unique: true,
    })
    public id!: number;

    @Column("varchar", {
        nullable: true,
        primary: false,
        unique: false,
    })
    public name?: string;
}

second.ts

import { Column, Entity } from "typeorm";

@Entity({ name: "second" })
export class Second {
    @Column("int", {
        nullable: false,
        primary: true,
        unique: true,
    })
    public notId!: number;

    @Column("varchar", {
        nullable: true,
        primary: false,
        unique: false,
    })
    public notName?: string;
}

query.ts

import { First } from "first.ts";

const results = await getConnection()
    .getRepository(First)
    .createQueryBuilder("a")
    .where("name = 'b'")
    .getMany();

Output (SQL)

select `a`.`notId`, `a`.`notName` from `second` `a` where `a`.`name` = 'b';

Note: this is not actually the code we have since I can't really make it public, but I can add some specifics if someone needs it.

For now going back to 0.2.19 fixes the issue though.

@0xMillz
Copy link
Contributor

0xMillz commented Feb 29, 2020

@mabintact Does the latest release 0.2.24 with commit e3be9e3 resolve this issue?

@mabintact
Copy link
Author

@mabintact Does the latest release 0.2.24 with commit e3be9e3 resolve this issue?

It's working great for me. :-)
I updated to 0.2.24 and everything I could thing to test is working great.

imnotjames added a commit to imnotjames/typeorm that referenced this issue Oct 2, 2020
in typeorm#4958 we found that the PR typeorm#4804 caused issues in a variety
of situations.  this adds a test to prevent the issue from recurring
where similar classes get mixed up in our metadata resolver
imnotjames added a commit that referenced this issue Oct 7, 2020
in #4958 we found that the PR #4804 caused issues in a variety
of situations.  this adds a test to prevent the issue from recurring
where similar classes get mixed up in our metadata resolver
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
in typeorm#4958 we found that the PR typeorm#4804 caused issues in a variety
of situations.  this adds a test to prevent the issue from recurring
where similar classes get mixed up in our metadata resolver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants