Heuristic:173TECH Sayn From Prod Glob Patterns
| Knowledge Sources | |
|---|---|
| Domains | Data_Engineering, Dev_Prod_Workflow |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
Glob-pattern-based source resolution that lets dev environments read specific prod tables without duplicating dev copies, using regex-converted wildcard patterns.
Description
SAYN's `from_prod` mechanism allows a development environment to read directly from production tables instead of dev-transformed versions. It works by converting glob-style patterns (using `*` wildcards) into regex patterns at init time, then checking each source DbObject's raw name against those patterns. When a source matches, the prod stringify rules (prefix/suffix/override) are applied instead of the dev rules. The patterns can be set via `settings.yaml` (`from_prod` key in a profile) or via the `SAYN_FROM_PROD` environment variable (comma-separated list).
The `TableGlob` pydantic validator converts the wildcard `*` into `.*` regex syntax, so patterns like `analytics.*` match all tables in the `analytics` schema. Additionally, individual sources can be marked as from-prod through the `sources_from_prod` set, which is populated during DAG construction.
Usage
Use this heuristic when setting up a dev/prod workflow where you need development tasks to read from production tables rather than dev copies. This is useful when dev databases are subsets or copies, but certain reference/dimension tables should always come from production to ensure accuracy.
The Insight (Rule of Thumb)
- Action: Set `from_prod` in your `settings.yaml` profile or `SAYN_FROM_PROD` environment variable.
- Value: Comma-separated glob patterns (e.g., `analytics.dim_*,reference.*`); wildcards use `*` which is converted to regex `.*`.
- Trade-off: Sources matching from_prod patterns will use prod table names — dev transformations are bypassed for those reads, which means dev schema prefixes/suffixes are NOT applied.
- Compatibility: Only affects source resolution (`src()` calls); output (`out()`) always uses dev stringify. Only applies to objects on the `default_db` connection.
Reasoning
In a typical dev/prod setup, all tables get dev prefixes (e.g., `dev_schema.table`). However, some tables — especially reference/dimension tables — may not have dev copies and must be read from prod. Without `from_prod`, dev tasks would look for `dev_schema.dim_date` and fail because it doesn't exist. The from_prod mechanism lets you specify which sources should skip dev transformation and read from prod directly.
The regex conversion happens in `TableGlob.validate()` (`settings.py:44-49`):
out = ""
if m.groupdict()["schema"] is not None:
out += m.groupdict()["schema"].replace("*", ".*") + r"\."
if m.groupdict()["table"] is not None:
out += m.groupdict()["table"].replace("*", ".*")
The matching logic in `DbObjectCompiler.is_from_prod()` (`objects.py:124-139`) only applies to the default database connection:
def is_from_prod(self, obj: DbObject) -> bool:
if obj.connection_name == self.default_db:
for regex in self.from_prod:
m = regex.match(obj.raw)
if m is not None:
return True
for source in self.sources_from_prod:
if source == obj:
return True
return False