Skip to content

Query engine: default values should be settable #964

@steebchen

Description

@steebchen

Fields marked with the @updatedAt or @default(...) directives are currently ignored when running a CreateOne mutation.

model User {
	id        String   @id @default(cuid())
	createdAt DateTime @default(now())
	updatedAt DateTime @updatedAt
	str       String
	int       Int
	float     Float
	bool      Boolean
	date      DateTime
}

image

First, I think it’s a bit inconsistent, as @id is also a @default but can also be overridden. Also, just by definition, default values provide defaults; they shouldn't prevent you from setting them.

Second, I think settings these values should be allowed for testing applications. Currently, my use-case is testing generators (Photon Go), as I can just compare the full result of any query. This requires me to set createdAt and updatedAt to default values like 2000-01-01T00:00:00Z, otherwise they get set to the current time which is not good for testing.

I think this should be possible just for the sake of testing. End-users may also write tests, in which case they would have the same problem if it’s not possible to set these values.

I also think there’s a good chance that users may want to set createdAt in some cases for whatever reasons; maybe they have some special use case where they need to set it to an earlier date.

Metadata

Metadata

Assignees

Labels

bug/2-confirmedBug has been reproduced and confirmed.kind/bugA reported bug.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions