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

Datetime microsecond precision dropped by query builder #804

Open
Oblynx opened this issue Aug 21, 2023 · 6 comments · May be fixed by #805
Open

Datetime microsecond precision dropped by query builder #804

Oblynx opened this issue Aug 21, 2023 · 6 comments · May be fixed by #805

Comments

@Oblynx
Copy link

Oblynx commented Aug 21, 2023

Bug description

I have a model with a column of type DateTime @db.timestamptz(6) as primary key. Microsecond precision is essential in this application. I try to create multiple rows with the same millisecond but different microseconds and Prisma throws a UniqueViolationError.

How to reproduce

TODO: complete MVE

With this model:

model MetadataMarkers {
  metadataID   BigInt
  timestamp     DateTime              @db.Timestamptz(6)
  marker  Json
  @@id([metadataID, timestamp])

Expected behavior

All the rows are added successfully.

Environment & setup

  • OS: Fedora 37
  • Database: Postgresql
  • Python version: 3.11.4
  • Prisma version:
prisma                  : 4.15.0
prisma client python    : 0.9.1
platform                : debian-openssl-1.1.x
expected engine version : 8fbc245156db7124f997f4cecdd8d1219e360944
installed extras        : []
install path            : /microservices/workspace/.venv/lib/python3.11/site-packages/prisma
binary cache dir        : /home/vscode/.cache/prisma-python/binaries/4.15.0/8fbc245156db7124f997f4cecdd8d1219e360944
@Oblynx
Copy link
Author

Oblynx commented Aug 21, 2023

After some digging, I can locate the issue at the prisma QueryBuilder.
In this screenshot, on the debugger pane (right), you see that the QueryBuilder arguments have microsecond precision. However, the builder.build() only has millisecond precision.

image

@Oblynx
Copy link
Author

Oblynx commented Aug 21, 2023

Digging deeper, it turns out that the precision is lost when rendering the Data node of the builder. Compare the timestamp in the fields children and data.

image

@Oblynx
Copy link
Author

Oblynx commented Aug 21, 2023

The root cause is the fix of this older issue: #129

@Oblynx
Copy link
Author

Oblynx commented Aug 21, 2023

IIUC, #129 was a workaround when Prisma didn't support microsecond precision in the field type definition. However, it now does. Therefore, I propose removing this old behavior.

Oblynx added a commit to Oblynx/prisma-client-py that referenced this issue Aug 21, 2023
closes RobertCraigie#804

- [ ] Unit tests for the changes exist
- [ ] Tests pass without significant drop in coverage
- [ ] Documentation reflects changes where applicable
- [ ] Test snapshots have been
[updated](https://prisma-client-py.readthedocs.io/en/latest/contributing/contributing/#snapshot-tests)
if applicable

By submitting this pull request, I confirm that you can use, modify,
copy and redistribute this contribution, under the terms of your choice.
@Oblynx Oblynx linked a pull request Aug 21, 2023 that will close this issue
8 tasks
@RobertCraigie
Copy link
Owner

Ah awesome, I was not aware Prisma now supports microsecond precision.

Thanks for investigating and opening a PR!

@Oblynx
Copy link
Author

Oblynx commented Aug 22, 2023

I hope to keep them coming! I'm really happy to use Prisma from python at work <3

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

Successfully merging a pull request may close this issue.

2 participants