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

Dates serialized without quotation marks in query event parameters property #6578

Closed
ssukienn opened this issue Apr 14, 2021 · 6 comments · Fixed by prisma/prisma-engines#3120
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine tech/engines Issue for tech Engines. topic: logging
Milestone

Comments

@ssukienn
Copy link

ssukienn commented Apr 14, 2021

Bug description

The dates in Prisma query event parameters property are serialized without " making it impossible to parse is as JSON out of the box.
Example:
["DRAFT","test-tenant-uuid","ONGOING","SCHEDULED","COMPLETED",2021-04-14 13:25:26.778 UTC,2021-04-14 13:25:26.779 UTC,101,0]. String values are enclosed with ", numbers naturally are not (but it is fine). With dates on the other hand it is not okay. If normal literal values are enclosed why not dates if they are stored in a property of type string. Additionally in SQL queries Date type columns are comparable with string representation.

How to reproduce

  1. Register event handler:
prisma.$on('query' as any, async (e) => {
            const eventObj = e as Prisma.QueryEvent;
            const params = JSON.parse(eventObj.params); // error
  1. Run any query with date/datetime filter parameters:
...
where: {
  startDate: { gte: filters?.dates?.[0] },
  endDate: { lte: filters?.dates?.[1] },
},
// filters.dates is an 2 element array of js Date type and both columns are of type DateTime

Expected behavior

Well, keeping the parameters in an array serialized to string is problematic in the first place but it wouldn't be a problem if we could parse it as a JSON, and I expected that it is always possible. If not and it is okay, is it really expected here to fix it by hand using string regexes/split/joins etc?

My use case here is that I am developing pretty debug log of the queries which can executed on the db 1:1.

Prisma information

Not relevant.

Environment & setup

  • OS: Windows 10
  • Database: MySQL 8+
  • Node.js version: 15.10
  • Prisma version: ^2.20.1

Internal Slack Thread

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: logging labels Apr 16, 2021
@matthewmueller

This comment has been minimized.

@ssukienn

This comment has been minimized.

@matthewmueller matthewmueller added the tech/typescript Issue for tech TypeScript. label Aug 10, 2021
@brave-coder9
Copy link

Hello @matthewmueller same issue here.. :( @ssukienn did you find a workaround?

@ssukienn
Copy link
Author

ssukienn commented Sep 27, 2021

I wasn't testing new Prisma versions for this bug and I no longer need it (a fix would be appreciated though) but as in the main post what you could do is reconcile with replacing ISO date or just format regex (plus delimiters) with captured value and enclosing quotation/delimiters like ,"${capturedDateGroup}",.

It is error-prone though and relies on the Prisma internals plus it would be worth checking how Prisma is encoding cases where certain string parameter is something like ... ,${date}, .... I would assume it is escaped somehow. Then you would need to handle this case also for better reliability.

@rottmann
Copy link

Or simple JSON.stringify it, so we can parse it.

@SevInf
Copy link
Contributor

SevInf commented May 24, 2022

The arguments are serialized on the engine side, client just forwards this string as-is

@SevInf SevInf added tech/engines Issue for tech Engines. tech/engines/query engine Issue in the Query Engine and removed tech/typescript Issue for tech TypeScript. labels May 24, 2022
@SevInf SevInf removed their assignment May 24, 2022
cprieto added a commit to prisma/quaint that referenced this issue Aug 11, 2022
 - Certain types, `Date`, `DateTime`, `Xml`, `UUID`, `Time` are displayed as quoted values in logging messages
 - This is part of fix for prisma/prisma#6578
cprieto added a commit to prisma/quaint that referenced this issue Aug 11, 2022
* Display parameters for certain types is done correctly

 - Certain types, `Date`, `DateTime`, `Xml`, `UUID`, `Time` are displayed as quoted values in logging messages
 - This is part of fix for prisma/prisma#6578
cprieto added a commit to prisma/prisma-engines that referenced this issue Aug 12, 2022
garrensmith pushed a commit to prisma/prisma-engines that referenced this issue Aug 18, 2022
@Jolg42 Jolg42 added this to the 4.3.0 milestone Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. tech/engines/query engine Issue in the Query Engine tech/engines Issue for tech Engines. topic: logging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants