-
Notifications
You must be signed in to change notification settings - Fork 149
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
forSchema mutates passed options #312
Comments
In fact, what's the reason for exposing |
Hi @bdrobinson. The registry is used for example to support custom I agree that mutating the options object can be surprising. Since changing this behavior would not be backwards-compatible, it will be best done with the next major release. Let's keep this open to track it. In the meantime, you can work around your underlying issue by adding the type hook below to function typeHook(schema, opts) {
let name = schema.name;
if (!name) {
return; // Not a named type, use default logic.
}
if (!~name.indexOf('.')) {
// We need to qualify the type's name.
const namespace = schema.namespace || opts.namespace;
if (namespace) {
name = `${namespace}.${name}`;
}
}
// Return the type registered with the same name, if any.
return opts.registry[name];
} See also #294 for more context. |
@mtth - appreciate this is an old thread at this point, but the When attempting to decode a Let me know if I've missed something important. Alternatively is there a world in which we could add an extra option into |
Given the following code:
The code unexpectedly crashes when we try and parse
userSchemaV2
with the error:Error: duplicate type name: User
.I looked at the source code and the problem is that
forSchema
mutates the passedopts
to add aregistry
to it. So it tries to parse the second schema butUser
is already in the registry, so it crashes. Here's the offending line:avsc/lib/types.js
Line 120 in f69d61c
It feels like very confusing behaviour that the top-level
opts
object is mutated in any way, and in fact has led to a crash for us when using https://github.com/kafkajs/confluent-schema-registry/, because that repo re-uses the options object between calls toforSchema
– see https://github.com/kafkajs/confluent-schema-registry/blob/b342f4eb42599447a39c9506ca501e3a59afc7c3/src/cache.ts#L28Thanks very much. Hope that makes sense, let me know if you need any more information.
The text was updated successfully, but these errors were encountered: