Skip to content

Conversation

@theyostalservice
Copy link
Contributor

@theyostalservice theyostalservice commented Nov 8, 2025

Problem

Problems:

  1. The validation for metric names should not allow hyphens. They are already disallowed in dbt-semantic-interfaces and metricflow, and the error message here correctly identifies that they're not allowed, but a mistake in the regex allows them to slip through.
  2. These name errors are validation errors, not parsing errors, and should be treated as such.
  3. We don't have any tests showing that these work and protecting them during maintenance.

Solution

Fix the regex, change the error type that we raise, and add tests!

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@cla-bot cla-bot bot added the cla:yes label Nov 8, 2025
Copy link
Contributor Author

theyostalservice commented Nov 8, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

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
@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2025

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
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.93%. Comparing base (11ada88) to head (ef95e92).

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     
Flag Coverage Δ
integration 88.81% <100.00%> (-0.12%) ⬇️
unit 65.20% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 65.20% <100.00%> (+0.02%) ⬆️
Integration Tests 88.81% <100.00%> (-0.12%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@theyostalservice theyostalservice force-pushed the patricky/fix-metric-name-validation-and-add-tests branch from a3a50af to ef95e92 Compare November 8, 2025 00:10
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"])):
Copy link
Contributor Author

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.",
                )
            )

@theyostalservice theyostalservice marked this pull request as ready for review November 8, 2025 00:25
@theyostalservice theyostalservice requested a review from a team as a code owner November 8, 2025 00:25
@github-actions github-actions bot added the community This PR is from a community member label Nov 8, 2025
@theyostalservice theyostalservice mentioned this pull request Nov 8, 2025
5 tasks
Copy link
Contributor

@QMalcolm QMalcolm left a 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

Copy link
Contributor Author

Yes, that's the correct understanding! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla:yes community This PR is from a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants