Title: On-demand feature view UDFs lose their module globals when rebuilt from the registry, so serving fails with NameError · Issue #6815 · feast-dev/feast · GitHub
Open Graph Title: On-demand feature view UDFs lose their module globals when rebuilt from the registry, so serving fails with NameError · Issue #6815 · feast-dev/feast
X Title: On-demand feature view UDFs lose their module globals when rebuilt from the registry, so serving fails with NameError · Issue #6815 · feast-dev/feast
Description: Expected Behavior An OnDemandFeatureView whose UDF calls a helper (or reads a constant/import) defined at its own module level should keep working when the view is loaded back from the registry — e.g. in a feature server, or any process ...
Open Graph Description: Expected Behavior An OnDemandFeatureView whose UDF calls a helper (or reads a constant/import) defined at its own module level should keep working when the view is loaded back from the registry — e...
X Description: Expected Behavior An OnDemandFeatureView whose UDF calls a helper (or reads a constant/import) defined at its own module level should keep working when the view is loaded back from the registry — e...
Opengraph URL: https://github.com/feast-dev/feast/issues/6815
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"On-demand feature view UDFs lose their module globals when rebuilt from the registry, so serving fails with NameError","articleBody":"## Expected Behavior\n\nAn OnDemandFeatureView whose UDF calls a helper (or reads a constant/import) defined\nat its own module level should keep working when the view is loaded back from the\nregistry — e.g. in a feature server, or any process that did not define the view itself.\n\n## Current Behavior\n\nThe UDF is rebuilt from its stored source text only, so every name it resolves from\nits defining module is missing, and the transformation fails at call time:\n\n```\nNameError: name 'scaled' is not defined\n```\n\n`PandasTransformation.from_proto` / `PythonTransformation.from_proto` prefer\n`rehydrate_udf_from_source` over the stored dill body. That function `exec`s **only the\nfunction's own source** into a fresh namespace seeded with just `pd`/`pandas`/`np`/`numpy`\n(`sdk/python/feast/transformation/udf_rehydrate.py:102`), so a module-level helper,\nconstant, or an import under any other alias is not present.\n\nThe `exec` itself still succeeds, because a function body's free variables are only\nresolved when the function is *called*. So `resolve_udf`\n(`sdk/python/feast/transformation/udf_rehydrate.py:160`) treats rehydration as\nsuccessful and **never falls back to the dill body** — even when that body would have\nworked. The failure surfaces later, during retrieval.\n\n## Steps to reproduce\n\nApply an ODFV from a script/notebook, so dill serializes the UDF by value and captures\nits globals:\n\n```python\nSCALE = 100.0\n\ndef scaled(x):\n return x * SCALE\n\n@on_demand_feature_view(\n sources=[stats, req],\n schema=[Field(name=\"conv_rate_scaled\", dtype=Float64)],\n)\ndef scaled_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_scaled\"] = scaled(inputs[\"conv_rate\"]) + inputs[\"bonus\"]\n return df\n\nfs.apply([driver, src, stats, req, scaled_rate])\nfs.materialize_incremental(datetime(2026, 6, 1))\n```\n\nThen read it back in a separate process that only has the registry (what a feature\nserver does):\n\n```python\nfs = FeatureStore(repo_path=\".\")\nfs.get_online_features(\n features=[\"driver_stats:conv_rate\", \"scaled_rate:conv_rate_scaled\"],\n entity_rows=[{\"driver_id\": 1001, \"bonus\": 1.0}],\n).to_dict()\n# NameError: name 'scaled' is not defined\n```\n\nMonkeypatching `from_proto` back to the previous dill-only behaviour, in the same\nprocess and against the same registry, returns the correct result:\n\n```python\n@classmethod\ndef _old_from_proto(cls, p):\n return PandasTransformation(udf=dill.loads(p.body), udf_string=p.body_text)\n\nPandasTransformation.from_proto = _old_from_proto\n# -> conv_rate_scaled=[51.0]\n```\n\nSo the registry demonstrably holds a working body that is being ignored.\n\nBoth transformation modes are affected — a bare proto round-trip is enough to show it:\n\n```python\nt = PythonTransformation(udf=py_udf, udf_string=src) # py_udf calls helper()\nrt = PythonTransformation.from_proto(t.to_proto())\n\nt.udf({\"a\": [1, 2]}) # {'out': [3, 6]}\nrt.udf({\"a\": [1, 2]}) # NameError: name 'helper' is not defined\n```\n\n### Specifications\n\n- Version: `master` @ `5ad5592390febfca60c9d88edf7daccbdd156fd6` (source-first rehydration added in #6655)\n- Platform: Linux x86_64, Python 3.11.15\n- Subsystem: on-demand feature views / transformation serialization\n\n## Possible Solution\n\nMake the \"is this rehydrated callable usable?\" check non-vacuous before accepting it.\nWalk the compiled function's `co_names` (recursively through nested code objects) and\nconfirm each is resolvable in the exec namespace or in builtins; if any name is missing,\nreturn `None` so `resolve_udf` falls back to the dill body as it did before.\n\nA `NameError`-catching wrapper that retries via dill on first call would also work, but\nvalidating up front keeps the failure out of the serving path entirely.\n\nWorth noting this is distinct from #5620, which covers the dill-by-reference case where\nthe defining module genuinely is not importable. The problem here is that source-first\nrehydration is chosen even when the stored dill body would succeed, so a setup that\npreviously served correctly now raises.\n\nI'm happy to put up a PR for this if the validate-then-fall-back approach looks right.\n","author":{"url":"https://github.com/Daksha1611","@type":"Person","name":"Daksha1611"},"datePublished":"2026-09-06T17:16:31Z","url":"https://github.com/feast-dev/feast/issues/6815"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e0345ee7-f0ff-5979-c551-fc166886a245 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B032:2826BD:E3559B:12AEC04:6AFE922B |
| html-safe-nonce | 51b927d077a8e75a4dd8f46b203d7368b7790a36f7f14aa33a7d8d297e70feed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDMyOjI4MjZCRDpFMzU1OUI6MTJBRUMwNDo2QUZFOTIyQiIsInZpc2l0b3JfaWQiOiI4MzQ3NDMxMDQ5NzkyNDM1NjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b3030661bf106cadc16ba3105167895a56b66d8b4ebf1c46078058b83781b2bc |
| hovercard-subject-tag | issue:5366471921 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/feast-dev/feast/6815/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4340efab21e70ad0cdaec4ce9f2ff349d8aad15feb4cd15f9a980516dceb6d8b/feast-dev/feast/issues/6815 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4340efab21e70ad0cdaec4ce9f2ff349d8aad15feb4cd15f9a980516dceb6d8b/feast-dev/feast/issues/6815 |
| og:image:alt | Expected Behavior An OnDemandFeatureView whose UDF calls a helper (or reads a constant/import) defined at its own module level should keep working when the view is loaded back from the registry — e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Daksha1611 |
| hostname | github.com |
| expected-hostname | github.com |
| None | b3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86 |
| turbo-cache-control | no-preview |
| go-import | github.com/feast-dev/feast git https://github.com/feast-dev/feast.git |
| octolytics-dimension-user_id | 57027613 |
| octolytics-dimension-user_login | feast-dev |
| octolytics-dimension-repository_id | 161133770 |
| octolytics-dimension-repository_nwo | feast-dev/feast |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 161133770 |
| octolytics-dimension-repository_network_root_nwo | feast-dev/feast |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a10310af51a1bfffbedc4fd81cb582acf0cb0ff |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width