{"record":{"id":"e8b5a929e9865fd9","repo":"databendlabs/databend","slug":"token-does-not-belong-to-this-contextvar","errorCode":null,"errorMessage":"Token does not belong to this ContextVar","messagePattern":"Token does not belong to this ContextVar","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/query/script_udf_support/src/transform_udf_script.rs","lineNumber":650,"sourceCode":"\n            def get(self, default=_MISSING):\n                value = getattr(self._local, \"value\", _MISSING)\n                if value is _MISSING:\n                    if default is not _MISSING:\n                        return default\n                    if self.default is _MISSING:\n                        raise LookupError(f\"ContextVar {self.name} has no value\")\n                    return self.default\n                return value\n\n            def set(self, value):\n                old = getattr(self._local, \"value\", _MISSING)\n                self._local.value = value\n                return Token(self, old)\n\n            def reset(self, token):\n                if token.var is not self:\n                    raise ValueError(\"Token does not belong to this ContextVar\")\n                if token.old is _MISSING:\n                    if hasattr(self._local, \"value\"):\n                        del self._local.value\n                else:\n                    self._local.value = token.old\n\n        class Context:\n            def __init__(self, values=None):\n                self._values = values or {}\n\n            def __setitem__(self, key, value):\n                self._values[key] = value\n\n            def items(self):\n                return self._values.items()\n\n            def run(self, callable, *args, **kwargs):\n                tokens = []","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/script_udf_support/src/transform_udf_script.rs#L632-L668","documentation":"This is a proc-macro compile-time error from derive(Visit)/derive(WalkMut): the visitor derive supports structs and enums but has no implementation for Rust unions. Applying the derive to a union type aborts compilation with this message at the union's span.","triggerScenarios":"Annotating a `union` definition with #[derive(Visit)] or #[derive(WalkMut)] in the query AST codebase.","commonSituations":"Refactoring an enum/struct into a union for FFI or memory-layout reasons while keeping the derive; copy-pasting a derive list onto a new union type.","solutions":["Remove the Walk/Visit derive from the union and implement the visitor manually.","Restructure the type as an enum or struct instead of a union.","Wrap the union in a newtype struct/enum that carries a manual Walk impl."],"exampleFix":"// before\n#[derive(Visit)]\nunion Raw { i: u64, f: f64 }\n// after\nimpl<'ast> Visit<'ast> for Raw { /* manual impl */ }","handlingStrategy":"type-guard","validationCode":"// compile-time: ensure derive targets are struct or enum\nconst _: () = { assert!(std::mem::size_of::<MyType>() > 0); }; // cannot detect union at runtime; check the source type before deriving","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never apply Walk/Visit derives to unions","Recheck derive lists when converting enums to unions","Prefer enums over unions for AST-adjacent types"],"tags":["rust","proc-macro","compile-time","ast"],"backgroundTag":"unsupported-operation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}