-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Stop allowing hyphens in metric names and add name validation tests #12158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Stop allowing hyphens in metric names and add name validation tests #12158
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
1 similar comment
|
Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12158 +/- ##
==========================================
- Coverage 91.98% 91.93% -0.05%
==========================================
Files 203 203
Lines 24847 24847
==========================================
- Hits 22856 22844 -12
- Misses 1991 2003 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
a3a50af to
ef95e92
Compare
| if not (re.match(r"^[A-Za-z]", data["name"])): | ||
| errors.append("must begin with a letter") | ||
| if not (re.match(r"[\w-]+$", data["name"])): | ||
| if not (re.match(r"[\w]+$", data["name"])): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh, I can't help but think it might make more sense to try to unify this regex and pull it directly from dbt-semantic-interfaces, but with all the changes afoot with that repo and metricflow right now, it seems better to avoid the added workflow complexity.
But, for reference, here is the different but definitely-not-allowing hyphens regex fron dsi:
NAME_REGEX = re.compile(r"\A[a-z]((?!__)[a-z0-9_])*[a-z0-9]\Z")
@staticmethod
def check_valid_name( # noqa: D
name: str, context: Optional[ValidationContext] = None
) -> Sequence[ValidationIssue]:
issues: List[ValidationIssue] = []
if not UniqueAndValidNameRule.NAME_REGEX.match(name):
issues.append(
ValidationError(
context=context,
message=f"Invalid name `{name}` - names may only contain lower case letters, numbers, "
f"and underscores. Additionally, names must start with a lower case letter, cannot end "
f"with an underscore, cannot contain dunders (double underscores, or __), and must be "
f"at least 2 characters long.",
)
)
QMalcolm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@theyostalservice is my understanding correct that these were raising an error previously on the MetricFlow side, but just not in core? I ask because if so, this should be good as is. If no error was being raised anywhere then we'd have to do some additional handling in code as it'd be a breaking change
|
Yes, that's the correct understanding! :-) |

Problem
Problems:
Solution
Fix the regex, change the error type that we raise, and add tests!
Checklist