`findMany` DateTime queries not finding applicable records
See original GitHub issueBug description
This bug was originally reported in https://github.com/RobertCraigie/prisma-client-py/issues/214 but was found to be an internal Query Engine issue as an equivalent Prisma Client query written in TypeScript yields the same unexpected behaviour.
How to reproduce
schema.prisma
// database
datasource db {
provider = "sqlite"
url = "file:database.db"
}
// generator
generator client {
provider = "prisma-client-js"
}
model Demo {
id Int @id
created_at DateTime @default(now())
}
prisma db push
- Open sqlite:
sqlite3 database.db
- Insert the record:
INSERT INTO Demo (id) VALUES (1);
- Confirm the records existence:
SELECT * FROM Demo;
- Run the script below
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function main() {
const today = new Date();
console.log(today);
const records = await prisma.demo.findMany({
where: {
created_at: {
lt: today,
},
},
});
console.log(records);
console.log(await prisma.demo.findMany())
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
});
Output:
2022-01-08T11:09:09.035Z
[]
[ { id: 1, created_at: 2022-01-08T10:26:59.000Z } ]
There are more detailed tests included in the original reproduction: https://github.com/iiian/prisma_python_datefailure_demo/blob/master/demo.py
Expected behavior
The record should be found in the first query:
[ { id: 1, created_at: 2022-01-08T10:26:59.000Z } ]
Environment & setup
- OS: Mac OS
- Database: SQLite
- Node.js version: v17.1.0
Prisma Version
prisma : 3.7.0
@prisma/client : 3.7.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 8746e055198f517658c08a0c426c7eec87f5a85f (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 8746e055198f517658c08a0c426c7eec87f5a85f
Studio : 0.445.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Prisma Client API (Reference)
findUniqueOrThrow retrieves a single data record in the same way as findUnique . However, if the query does not find a record, it...
Read more >Prisma 2 query to return records only that are associated with ...
I created your model in Prisma 2 and used the following command to get a single principle that has the two tags associated...
Read more >Date criteria doesn't work in my query - Microsoft Support
Getting unexpected or no results when you include date criteria in a query? Learn about some of the reasons why this happens.
Read more >Query | GORM - GORM
Additionally, if no primary key is defined for relevant model, then the model will be ordered by the first ... This query would...
Read more >GraphQL Search and Filter – How to search and filter results ...
Searching and filtering is a standard part of any GraphQL API. ... The following query asks for albums with the ids 1 ,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also should be noted that this bug does not occur when the record is created within Prisma, for example:
Output:
Using raw queries causes the original error:
Not an issue for MySQL.