Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(cdp): make remote config sync survive HogFunction schema drift (#77354)

posthog[bot]020a31214d61
diff --git a/posthog/models/remote_config.py b/posthog/models/remote_config.py
index 429741e5d505..b769b5bb665f 100644
--- a/posthog/models/remote_config.py
+++ b/posthog/models/remote_config.py
@@ -366,33 +366,38 @@ class RemoteConfig(UUIDTModel):
f"\n{{\n id: '{site_app.token}',\n init: function(config) {{\n {indent_js(site_app.source, indent=4)}().inject({{ config:{json.dumps(config)}, posthog:config.posthog }});\n config.callback(); return {{}} }}\n}}"
)
)
- site_functions = (
- HogFunction.objects.select_related("team")
- .filter(
- team=self.team,
- enabled=True,
- deleted=False,
- type__in=("site_destination", "site_app"),
- )
- .all()
- )
-
site_functions_js = []
- for site_function in site_functions:
- try:
- source = get_transpiled_function(site_function)
- # NOTE: It is an object as we can later add other properties such as a consent ID
- # Indentation to make it more readable (and therefore debuggable)
- site_functions_js.append(
- indent_js(
- f"\n{{\n id: '{site_function.id}',\n init: function(config) {{ return {indent_js(source, indent=4)}().init(config) }} \n}}"
- )
+ try:
+ site_functions = (
+ HogFunction.objects.select_related("team")
+ .filter(
+ team=self.team,
+ enabled=True,
+ deleted=False,
+ type__in=("site_destination", "site_app"),
)
- except Exception:
- # TODO: Should we track this to somewhere?
- logger.exception(f"Failed to build JS for site function {site_function.id}")
- pass
+ .only("id", "team_id", "inputs", "hog", "filters", "mappings")
+ )
+
+ for site_function in site_functions:
+ try:
+ source = get_transpiled_function(site_function)
+ # NOTE: It is an object as we can later add other properties such as a consent ID
+ # Indentation to make it more readable (and therefore debuggable)
+ site_functions_js.append(
+ indent_js(
+ f"\n{{\n id: '{site_function.id}',\n init: function(config) {{ return {indent_js(source, indent=4)}().init(config) }} \n}}"
+ )
+ )
+ except Exception as e:
+ # Caught exceptions never reach error tracking on their own, and degrading
+ # silently here hides a broken site function from everyone.
+ logger.exception(f"Failed to build JS for site function {site_function.id}")
+ capture_exception(e)
+ except Exception as e:
+ logger.exception(f"Failed to fetch site functions for team {self.team.id}")
+ capture_exception(e)
return site_apps_js + site_functions_js
diff --git a/posthog/models/test/test_remote_config.py b/posthog/models/test/test_remote_config.py
index afff307b97c0..8183969bbbc8 100644
--- a/posthog/models/test/test_remote_config.py
+++ b/posthog/models/test/test_remote_config.py
@@ -282,6 +282,15 @@ class TestRemoteConfig(_RemoteConfigBase):
list_limited_team_attributes.clear_cache()
+ def test_site_functions_query_failure_degrades_to_empty_list(self):
+ with patch(
+ "products.cdp.backend.models.hog_functions.hog_function.HogFunction.objects.select_related",
+ side_effect=Exception("column posthog_hogfunction.version does not exist"),
+ ):
+ result = self.remote_config._build_site_apps_js()
+
+ assert result == []
+
class TestRemoteConfigSurveys(_RemoteConfigBase):
# Largely copied from TestSurveysAPIList