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

Bug with @VirtualColumn not being returned correctly #10638

Open
1 of 18 tasks
macleysousa opened this issue Jan 17, 2024 · 19 comments · May be fixed by #10698 or #10777
Open
1 of 18 tasks

Bug with @VirtualColumn not being returned correctly #10638

macleysousa opened this issue Jan 17, 2024 · 19 comments · May be fixed by #10698 or #10777

Comments

@macleysousa
Copy link

Issue description

@VirtualColumn not being returned correctly

Expected Behavior

@Entity({ name: 'integrations' })
export class IntegrationEntity {
  @Exclude()
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty()
  @PrimaryColumn({ name: 'client_id', type: 'uuid' })
  client_id: string;

  @ApiProperty()
  @VirtualColumn({ query: (alias) => `select "DMS" from config_client where "client_id"=${alias}.client_id` })
  dms: string;
}

It was expected that @VirtualColumn would return the correct values according to the logic defined in the decorator.

{
  "client_id": "1b97a2d2-91b8-4dab-9593-906da6d95d36",
  "dms": "NBS"
}

Actual Behavior

@Entity({ name: 'integrations' })
export class IntegrationEntity {
  @Exclude()
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty()
  @PrimaryColumn({ name: 'client_id', type: 'uuid' })
  client_id: string;

  @ApiProperty()
  @VirtualColumn({ query: (alias) => `select "DMS" from config_client where "client_id"=${alias}.client_id` })
  dms: string;
}

DNS column is not being returned

{
  "client_id": "1b97a2d2-91b8-4dab-9593-906da6d95d36"
}

Steps to reproduce

  1. Add the @VirtualColumn decorator to an entity or class.
  2. Define the expected logic for the virtual value.
  3. Observe the obtained result.

My Environment

Dependency Version
Operating System windows 10
Node.js version 18.18.0
Typescript version 5.3.3
TypeORM version 0.3.19

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

@nodegin
Copy link

nodegin commented Jan 18, 2024

Same here, with latest 0.3.19.
Locking the version to 0.3.17 fixed it.
Not sure if breaking changes introduced in 0.3.18 or 0.3.19.

@nodegin
Copy link

nodegin commented Jan 18, 2024

@jorenvandeweyer
Copy link
Collaborator

How do you select the virtual column, can you give an example of the implementation?

@kevinwilson541
Copy link

kevinwilson541 commented Jan 18, 2024

As an example, usage of the repository findOne or findOneOrFail functions, without the select option, will return virtual columns by default in version 0.3.17. Version 0.3.19 omits virtual columns with the same usage pattern.

@NarHakobyan
Copy link

NarHakobyan commented Jan 19, 2024

Yeah, we are experiencing the same issue, virtual column stopped working. this is urgent‼️

@jorenvandeweyer
Copy link
Collaborator

Can you create a PR to fix the issue introduced in #10432 but also keep #10431 fixed? If not, I think we should create a PR reverting the changes from #10432

@macleysousa
Copy link
Author

@jorenvandeweyer
I think we should create a PR reverting the changes from #10432, because analyzing the code from PR #10432 it just made all virtual columns return null, in his case I think he should use a transformation to convert empty to null

@fatlirmorina
Copy link

Same here ->

Upgraded from 0.3.17 to 0.3.19 (latest) and everything related to VirtualColumn breaks.

@EliezerMafra
Copy link

Same here ->
the @VirtualColumn decorator does not work on 0.3.19 version

@PatrickWe
Copy link

I have the Same issue.

Upgraded from 0.3.17 to 0.3.19 and everything related to VirtualColumn breaks.

@AmrAnwar
Copy link

not working with us too after update from 0.3.17

@martin-scholz-emnify
Copy link

still broken in 0.3.20

@macleysousa macleysousa linked a pull request Feb 11, 2024 that will close this issue
7 tasks
@gwen1230
Copy link

Any news on open MR ?

@nodegin
Copy link

nodegin commented Feb 27, 2024

@gwen1230 I think they are not going to fix this because not much people are using virtual column, so for stability either downgrade or switch to Prisma instead.

@strongpauly
Copy link
Contributor

I've seen this too after upgrading. A possible workaround is to pass a select which includes the virtual column, but this isn't great as you then have to pass all the fields that you want to be returned.

@Dawar
Copy link

Dawar commented Mar 8, 2024

I've seen this too after upgrading. A possible workaround is to pass a select which includes the virtual column, but this isn't great as you then have to pass all the fields that you want to be returned.

Tried this but didn't seem to work, TypeORM is trying to load the column from the actual table. Did you have any success with it?

If the general direction is to manually select virtualcolumns that would also be fine (there should probably be an eager option on the decorator in that case). The previous virtualcolumn functionality was ideal imo. Curious why these breaking changes were implemented from a benefit stand-point.

Will try and compare prev and curr implementation for possible ideas

@d3tr1tus
Copy link

Any updates? I would appreciate some fix here it will be really helpful 🙏🏼

@ernes128
Copy link

any updates on this?

@tristin-terry
Copy link

A fix for this would be helpful, we were just affected by this in production and are going to have to downgrade or patch it internally until it is fixed!

hopefully either #10777 or #10698 can be reviewed soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment