-
Notifications
You must be signed in to change notification settings - Fork 35
Fix array based conversion of display labels for obsolete format #7434
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
Fix array based conversion of display labels for obsolete format #7434
Conversation
WalkthroughThis change refactors display label formatting in the schema module by introducing a centralized helper function to standardize component formatting. The helper function Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
CodSpeed Performance ReportMerging #7434 will not alter performanceComparing Summary
|
9819b15 to
076f2ef
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
backend/infrahub/core/schema/schema_branch.py (1)
2597-2607: Update docstring to follow Google style format.The docstring is missing required sections per the coding guidelines. Add
ArgsandReturnssections.Apply this diff:
def _format_display_label_component(component: str) -> str: - """Return correct format for display_label. + """Return correct format for display_label component. Previously both the format of 'name' and 'name__value' was supported this function ensures that the proper 'name__value' format is used + + Args: + component: The display label component to format + + Returns: + The formatted component with __value suffix when needed """ if "__" in component: return component return f"{component}__value"backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.py (1)
95-103: Remove unnecessaryasynckeyword.The test function is marked as
asyncbut contains noawaitcalls. Since the test performs only synchronous operations, theasynckeyword should be removed.Apply this diff:
-async def test_expected_final_display_label( +def test_expected_final_display_label( test_case: DisplayLabelTestCase, ) -> None: """Test that the final computed display label matches the expected value."""
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
backend/infrahub/core/schema/schema_branch.py(2 hunks)backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
backend/tests/**/*
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Place backend tests in
backend/tests/
Files:
backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.py
backend/**/*
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Run backend tests with
pytestor viainvoketasks
Files:
backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.pybackend/infrahub/core/schema/schema_branch.py
**/*.py
📄 CodeRabbit inference engine (.github/instructions/python-docstring.instructions.md)
**/*.py: Use triple double quotes (""") for all Python docstrings
Write docstrings in Google-style format
Include a brief one-line description at the top of each docstring
Add a detailed description section when additional context is needed
Document function/method parameters under an Args/Parameters section without typing information
Include a Returns section describing the return value
Include a Raises section listing possible exceptions
Provide an Examples section demonstrating usage when helpfulUse ruff and mypy to validate and lint Python files
**/*.py: Use type hints for all Python function parameters and return values
Prefer asynchronous code in Python when feasible
Define asynchronous Python functions withasync def
Useawaitfor asynchronous calls in Python
Use Pydantic models instead of standard dataclasses
Use ruff and mypy for linting and type checking
**/*.py: Use type hints for all Python function parameters and return values
Use async/await whenever possible in Python code
Define asynchronous functions withasync def
Await asynchronous calls withawait
Use Pydantic models instead of standard dataclasses for data modeling
Use triple quotes (""") for all Python docstrings
Write docstrings in Google-style format
Include docstring sections when applicable: one-line summary, optional details, Args (without types), Returns, Raises, Examples
Validate and lint Python with ruff and mypy
Files:
backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.pybackend/infrahub/core/schema/schema_branch.py
🧬 Code graph analysis (1)
backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.py (1)
backend/infrahub/core/schema/schema_branch.py (4)
load_schema(494-523)process(525-529)get_node(349-354)duplicate(280-289)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
backend/infrahub/core/schema/schema_branch.py (1)
796-808: LGTM: Display label conversion logic correctly handles both formats.The implementation properly converts legacy
display_labelsto the newdisplay_labelfield, supporting both short (e.g.,"name") and verbose (e.g.,"name__value") formats as described in the PR objectives. The helper function ensures consistent formatting across single and multi-attribute cases.backend/tests/unit/core/schema/schema_branch/test_schema_convert_display_labels.py (1)
9-88: Excellent test coverage for display label conversion scenarios.The test cases comprehensively cover all the conversion scenarios mentioned in the PR: single attribute (with/without
__value), dual attributes (mixed formats), and explicitly defined display labels. The parametrized approach makes it easy to understand each scenario.
| display_label: str | ||
|
|
||
|
|
||
| DISPLAY_LABEL_TEST_CASES: list[DisplayLabelTestCase] = [ |
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.
good pattern. easy to read
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.
Yeah, I agree we have it in a few places and I think we should do more of it. Especially for pytest.params with multiple variables.
For
display_labelswe supported both short and verbose attribute values i.e. both["name"]and["name__value"], this change ensures that we also support the same when migratingdisplay_labelstodisplay_labelwithin the SchemaBranch.Summary by CodeRabbit
Refactor
Tests