`convex-test` invalid identifier
Given this code:
It works as expected when the schema looks like this:
However, when a system field such as
_creationTime
is added to the schema, vitest
throws this error:
Error: Field names must be valid identifiers, got "_creationTime"
https://github.com/get-convex/convex-test/blob/83f7e271d41f086b16cfcf8f7efc53efd7491b19/index.ts#L838
Desired behaviour
Can convex-test
accept a schema with the same policy as defineSchema({...})
used in schema.ts
and not a more strict policy that doesn't allow for _creationTime
?
defineSchema({...})
allows the _creationTime
field.7 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
I see the difference in behavior you're pointing at, but can you help me understand the goal here? _creationTime is guaranteed (and required) for every Convex document. If _creationTime is accepted by defineTable, it still wouldn't result in any change to the definition of the field (eg., it can't be optional or of a different type).
I’m using a shared Zod schema to define my tables. This schema contains _creationTime as an optional value as it may or may not exist.
I understand passing _creationTime as part of the schema has no impact on the table created.
It’s working fine for defineSchema() so I would expect convex-test to parse the valid Convex schema without errors.
Thanks for looking into it and let me know if it needs further clarification.
Ah I see, it's ignored by the actual backend, so it's a convenience, but it's breaking in tests. Got it.
Looks like a pretty simple fix, would need an exception for '_creationTime' here: https://github.com/get-convex/convex-test/blob/83f7e271d41f086b16cfcf8f7efc53efd7491b19/index.ts#L846.
Not sure how the rest of the code would handle it, though.
Actually it looks like insert, patch, and replace all account for it with the same kind of logic as the backend.
GitHub
allow system fields in schema by erquhart · Pull Request #38 · ge...
This aligns with backend behavior. This is already supported in insert/patch/replace mocks, they just aren't allowed by the field validation regex.
Fixed in 0.0.37
This has fixed the issue - thanks @erquhart!