Skip to content

check_hard_coded_references

This check identifies models that are not using the ref or source macro to reference other tables.

Version History

Added in Debby v0.3.0

Parameters

This check does not support any custom parameters.

Info

For more information about how to set custom parameters for a check, see the documentation on configuration.

Source

def check(model: dict):
    regexes = [
        r"""(?ix)(?<!distinct\s)(from|join)\s+({{\s*var\s*\(\s*[\'\"]?)([^)\'\"]+)([\'\"]?\s*)(\)\s*}})""",
        r"""(?ix)(?<!distinct\s)(from|join)\s+({{\s*var\s*\(\s*[\'\"]?)([^)\'\"]+)([\'\"]?\s*)(,)(\s*[\'\"]?)([^)\'\"]+)([\'\"]?\s*)(\)\s*}})""",
        r"""(?ix)(?<!distinct\s)(from|join)\s+([\[`\"\']?)(\w+-?\w*)([\]`\"\']?)(\.)([\[`\"\']?)(\w+-?\w*)([\]`\"\']?)(?=\s|$)""",
        r"""(?ix)(?<!distinct\s)(from|join)\s+([\[`\"\']?)(\w+-?\w*)([\]`\"\']?)(\.)([\[`\"\']?)(\w+-?\w*)([\]`\"\']?)(\.)([\[`\"\']?)(\w+-?\w*)([\]`\"\']?)(?=\s|$)""",
        r"""(?ix)(?<!distinct\s)(from|join)\s+([\[`\"\'])(\w+-?\w+)([\]`\"\'])(?=\s|$)""",
    ]

    for regex in regexes:
        assert not re.search(regex, model["raw_code"])