Skip to content

Commit

Permalink
Update valid name regex to disallow dunders
Browse files Browse the repository at this point in the history
  • Loading branch information
QMalcolm committed Sep 14, 2023
1 parent ef8a893 commit 6568309
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230914-134708.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Disallow dunders semantic object names
time: 2023-09-14T13:47:08.907492-07:00
custom:
Author: QMalcolm
Issue: "149"
6 changes: 5 additions & 1 deletion dbt_semantic_interfaces/validations/unique_valid_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class UniqueAndValidNameRule(SemanticManifestValidationRule[SemanticManifestT],
* Names of semantic models, dimension sets and metric sets in the model are unique / valid.
"""

NAME_REGEX = re.compile(r"\A[a-z][a-z0-9_]*[a-z0-9]\Z")
# name must start with a lower case letter
# name must end with a number or lower case letter
# name may include lower case letters, numbers, and underscores
# name may not contain dunders (two sequential underscores
NAME_REGEX = re.compile(r"\A[a-z]((?!__)[a-z0-9_])*[a-z0-9]\Z")

@staticmethod
def check_valid_name(name: str, context: Optional[ValidationContext] = None) -> List[ValidationIssue]: # noqa: D
Expand Down
1 change: 1 addition & 0 deletions tests/validations/test_unique_valid_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def test_invalid_names() -> None: # noqa:D
assert UniqueAndValidNameRule.check_valid_name("_no_leading_underscore") != []
assert UniqueAndValidNameRule.check_valid_name("no_trailing_underscore_") != []
assert UniqueAndValidNameRule.check_valid_name("_definitely_no_leading_and_trailing_underscore_") != []
assert UniqueAndValidNameRule.check_valid_name("name__with__dunders") != []

# time granularity values are reserved
assert UniqueAndValidNameRule.check_valid_name("day") != []
Expand Down

0 comments on commit 6568309

Please sign in to comment.