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

generatedMaps for timestamps are being returned as string not Date #141

Open
calvin-cdev opened this issue Apr 6, 2022 · 2 comments
Open

Comments

@calvin-cdev
Copy link
Contributor

calvin-cdev commented Apr 6, 2022

Package versions and database engine type (please complete the following information):

  • Database Engine: postgres
  • TypeORM Version: 0.2.41
  • Driver Version 2.3.8

Describe the bug
When I do an insert for an entity with a generated date (timestamp) field like createdAt or updatedAt, the value in the resultant generatedMaps is a string, not a Date.
I would expect a Date object, just like I would get in the result of a find operation, but I end up getting a string. Worse, the string is missing the UTC Z at the end, so there is even more work to do to get it back to UTC time as a Date object.

Not only is the value on the generatedMaps incorrectly formatted, but also the mutated entity object passed into the insert call has the incorrectly formatted date:

const entity = { someField:  true }
await getRepository(Entity).insert(entity)

/** insert call mutated the object passed in.
*   now entity.createdAt exists and is not a Date, but a string.
*   more complete example in repro section. **/

I'd be happy to fix this, but I need guidance
I'm not sure where the fix should go. It could go into this driver package. It could go into typeorm. It could also go into the data-api-client.
I think it should go into the data-api-client, and here is why:
There was a PR to address this issue but the relevant part of the fix was dropped by the owner while addressing merge conflicts before merging the PR.
From the requester's findings and my own, it looks like aws sends the typeName from executeStatement commands back in lowercase for postgres 😬 . The code in the data-api-client is written only to compare against uppercase typeName values. I monkey-patched the package and found that this issue was indeed fixed. However, I'm not sure if this is actually the correct layer for the fix.
What do you think?

To Reproduce

be sure to use formatOptions.deserializeDate=true

entity class

@Entity()
export default class Event {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @CreateDateColumn()
  createdAt: Date;
  
  @Column({ type: 'boolean' })
  someField: boolean
}

use it

const entity = { someField:  true }
const result = await getRepository(Event).insert(entity)

view that the result has generatedMaps with createdAt as a timezone-less string. It should be a UTC Date.

@calvin-cdev
Copy link
Contributor Author

calvin-cdev commented Apr 7, 2022

opened a pr in the data-api-client repo to fix jeremydaly/data-api-client#117
worth noting that at the request of the author, this pr targets their aws sdk v3 migration branch, not main. so the fix won't be available until they release that version.

@ArsenyYankovsky
Copy link
Owner

Thanks for your contribution!
Reading about your findings it looks like the best would be to fix it in the data-api-client.
Let's keep this open until the PR is merged so we can upgrade to the fixed data-api-client version when it's released.

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

2 participants