question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dates serialized without quotation marks in query event parameters property

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ssukienncommented, Dec 2, 2021

No, I am not using this flag.

0reactions
SevInfcommented, May 24, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Database Engine events and errors - SQL Server
Unclosed quotation mark after the character string '%. *ls'. Too many table names in the query.
Read more >
JavaScript JSON Date Parsing and real Dates - Rick Strahl
JavaScript doesn't have a date literal, and for this reason JSON serializes dates as strings rather than real JavaScript dates.
Read more >
ASP.NET MVC JsonResult Date Format - Stack Overflow
If you are exchanging data with another application, you will need to check its documentation to see how it encodes date and time...
Read more >
Date, time, and timestamp literals - Amazon Redshift
A date or timestamp literal must be enclosed in quotation marks when you load it ... The following special values can be used...
Read more >
Dates and Times | Charts - Google Developers
The DataTable datetime column data type uses the same Date constructor as the date data type, but now uses all of the arguments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found