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

UUID "TypeError: Invalid schema configuration" #13241

Closed
2 tasks done
jmbldwn opened this issue Apr 3, 2023 · 5 comments
Closed
2 tasks done

UUID "TypeError: Invalid schema configuration" #13241

jmbldwn opened this issue Apr 3, 2023 · 5 comments
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity Stale

Comments

@jmbldwn
Copy link

jmbldwn commented Apr 3, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

7.0.3

Node.js version

16.19.1

MongoDB server version

4.2.0

Typescript version (if applicable)

No response

Description

Encountering what appears to be a bug in the UUID type. I have a single field I'm adding via a plugin and it looks like the schema merging is getting confused. The error message is pretty explanatory:

    TypeError: Invalid schema configuration: `00000000-0000-0000-0000-000000000000` is not a valid type at path `NIL`. See https://bit.ly/mongoose-schematypes for a list of valid schema types.

      15 |     // archived flags deleted devices.  GC later
      16 |
    > 17 |     schema.add({
         |            ^
      18 |         documentId: {
      19 |             type: mongoose.Schema.Types.UUID,
      20 |             default: uuidv4,

      at Schema.add (node_modules/mongoose/lib/schema.js:677:13)
      at new Schema (node_modules/mongoose/lib/schema.js:134:10)
      at Schema.add (node_modules/mongoose/lib/schema.js:743:25)
      at add (services/hub/models/syncable.js:17:12)
      at Schema.Object.<anonymous>.Schema.plugin (node_modules/mongoose/lib/schema.js:1884:3)
      at Object.plugin (services/hub/models/circuit.js:10:8)

I have no idea why the type is coming across as NIL. I've stepped through the code quite a bit and it looks like maybe the type definition for UUID is just wrong?

Steps to Reproduce

Define a schema type UUID and add it to an existing schema:

    schema.add({
        documentId: {
            type: mongoose.Schema.Types.UUID,
            default: uuidv4,
            index: true
        },

Expected Behavior

No error.

@jmbldwn
Copy link
Author

jmbldwn commented Apr 3, 2023

Hmmm. This appears to only happen when testing with Jest.

A workaround for an incompatibility between jest and uuid is tricking mongoose into screwing up the uuid import.

According to uuidjs/uuid#451, This should work with uuid 9.0.0 and jest 29.4.0, but i'm getting no love on this.

Any ideas?

@vkarpov15
Copy link
Collaborator

@jmbldwn can you please create a sample project that demonstrates this issue? We'd need more info, like Jest version, configs, etc. in order to repro this.

We would also strongly recommend using any testing framework other than Jest.

@vkarpov15 vkarpov15 added the needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity label Apr 4, 2023
@jmbldwn
Copy link
Author

jmbldwn commented Apr 4, 2023

I actually solved this with a crafty Jest mock. See my answer in https://stackoverflow.com/questions/73203367/jest-syntaxerror-unexpected-token-export-with-uuid-library/75924883#75924883

I agree on Jest; it's a pain but we're somewhat heavily invested in it. Any suggestions that would be an easy conversion?

@github-actions
Copy link

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Apr 19, 2023
@vkarpov15
Copy link
Collaborator

@jmbldwn without a closer look at your code, hard to say what would be an easy conversion. We make heavy use of Mocha and have for almost a decade now, that would be my recommendation, but the conversion may or may not be easy depending on how much Jest-specific stuff your codebase uses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity Stale
Projects
None yet
Development

No branches or pull requests

2 participants