-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use current instance schema controller #3454
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
fastify.js
Outdated
@@ -631,7 +631,7 @@ function fastify (options) { | |||
function setSchemaController (schemaControllerOpts) { | |||
throwIfAlreadyStarted('Cannot call "setSchemaController" when fastify instance is already started!') | |||
const old = this[kSchemaController] | |||
const parent = old.parent || old | |||
const parent = old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the issue is the plugin registration with a null ref, shouldn't this be smth like this?
const parent = old | |
const parent = old ? old.parent : old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly, the issue appears on every new registration of a SchemaController
, if you register a new one within a new encapsulated context, as the current context where the controller is being registered as a parent, any added schema within the current context is missed, causing to (in this case Ajv) totally missed such registered schemas.
By following the suggestion, see the result:
Having in mind that:
some
was registered in the root instanceanother
was registered in the child instance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test without a plugin for better explanation 馃檪
4877f81
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the parent
variable since it is no more useful.
To help understand what is going on here, be aware that the compilersFactory
is used only when necessary.
In this case, the root context does not use any schemas because it does not contain any route.
For this reason, the "main" compilers is not built.
As you can see, the plugin context instead uses a route and try to build the compilers, triggering the error (old
is null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 79213ce 馃憤
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
While still working on #3121 noticed when adding Schemas to child instances, these schemas were lost in the middle, causing any nested validation schema to fail the compilation step due to missing the schema(s) reference.
Note:
Checklist
npm run test
andnpm run benchmark
and the Code of conduct