Skip to content

Add ternary operator to fix bug related with empty key#18565

Merged
TheMilek merged 2 commits intoSylius:2.1from
michalkaczmarek-bitbag:bugfix/fix-error-during-rendering-data-table-hook
Jan 20, 2026
Merged

Add ternary operator to fix bug related with empty key#18565
TheMilek merged 2 commits intoSylius:2.1from
michalkaczmarek-bitbag:bugfix/fix-error-during-rendering-data-table-hook

Conversation

@michalkaczmarek-bitbag
Copy link
Copy Markdown
Contributor

@michalkaczmarek-bitbag michalkaczmarek-bitbag commented Nov 21, 2025

Q A
Branch? 2.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets #17718
License MIT

I reproduced error when chose nl_NL and ran command bin/console sylius:install. Bug was caused lack translations for taxons.

Summary by CodeRabbit

  • Bug Fixes

    • Admin product list now correctly handles products whose main category has no name — tooltips and category display no longer error or show incorrect content.
  • Tests

    • Added a UI scenario and step coverage to verify browsing products with unnamed main categories in the admin interface.

✏️ Tip: You can customize this high-level summary in your review settings.

@probot-autolabeler probot-autolabeler bot added the Admin AdminBundle related issues and PRs. label Nov 21, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 21, 2025

Walkthrough

Added handling for taxons with empty names: template now preserves data.fullname when data.name is empty; a Behat feature checks browsing products when a main taxon has no name; a new Behat step sets a taxon's name to an empty string in a given locale.

Changes

Cohort / File(s) Summary
Template: taxon display
src/Sylius/Bundle/AdminBundle/templates/product/grid/field/main_taxon.html.twig
Conditionalized categories assignment: if data.name is truthy, remove it from data.fullname; otherwise keep data.fullname unchanged (affects tooltip and conditional rendering that uses categories).
Behavioral test
features/admin/product/managing_products/browsing_products_with_main_taxon_without_name.feature
Added Behat feature to verify admin product listing when the main taxon has no name in the current locale.
Behat context: taxonomy setup
src/Sylius/Behat/Context/Setup/TaxonomyContext.php
Added theTaxonHasEmptyNameInLocale(TaxonInterface $taxon, string $localeCode) step (appears inserted twice) to set the taxon's translation name to an empty string and flush the unit of work.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant AdminUI as Admin UI
    participant Template as main_taxon template
    participant Product as Product Data
    participant Taxon as Taxon Data
    participant Behat as Behat Context

    Note over Behat,Taxon: Setup step may set taxon name to empty
    Behat->>Taxon: set translation name = ""
    Taxon-->>Product: product.mainTaxon (fullname, name)

    AdminUI->>Product: request product list
    Product->>Template: render main_taxon field with data.fullname & data.name
    alt data.name is truthy
        Template->>Template: categories = fullname.replace(name, '')
        Template-->>AdminUI: render name and tooltip with categories
    else data.name is empty/false
        Template->>Template: categories = fullname
        Template-->>AdminUI: render (empty) name and tooltip with fullname
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Template change is small but behavior-affecting; verify tooltip and conditional rendering.
  • New feature needs review for correctness and flakiness.
  • Context file shows the same method inserted twice — requires attention to remove duplication and ensure no conflicting declarations.

Possibly related PRs

Suggested reviewers

  • GSadee

Poem

🐰 I nibbled paths both long and bright,
If a name is gone, I keep the sight,
Fullname stays where emptiness creeps,
A rabbit guards the taxonomy sleeps. 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: adding a ternary operator to handle empty keys in taxon name rendering, which directly addresses the bug where missing translations cause rendering errors.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c714f46 and 2be6be0.

📒 Files selected for processing (2)
  • features/admin/product/managing_products/browsing_products_with_main_taxon_without_name.feature (1 hunks)
  • src/Sylius/Behat/Context/Setup/TaxonomyContext.php (1 hunks)
⏰ 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). (14)
  • GitHub Check: Packages / PHP 8.4, Symfony ^7.3
  • GitHub Check: Packages / PHP 8.3, Symfony ^6.4
  • GitHub Check: End-to-end tests (PostgreSQL) / Non-JS, PHP 8.4, Symfony ^7.3, PostgreSQL 17.5
  • GitHub Check: End-to-end tests (PostgreSQL) / Non-JS, PHP 8.3, Symfony ^6.4, PostgreSQL 15.13
  • GitHub Check: Frontend / NodeJS 24.x
  • GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.3, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
  • GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.3, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
  • GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.4, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
  • GitHub Check: End-to-end tests (MySQL) / JS with Panther, PHP 8.3, Symfony ^6.4 (test_cached), MySQL 8.0, Twig ^3.3
  • GitHub Check: End-to-end tests (MySQL) / Non-JS, PHP 8.4, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
  • GitHub Check: End-to-end tests (MySQL) / JS with Chromedriver, PHP 8.4, Symfony ^7.3 (test_cached), MySQL 8.4, Twig ^3.3
  • GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.3, Symfony ^6.4, MariaDB 10.11.13, State Machine Adapter winzou_state_machine
  • GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.4, Symfony ^7.3, MariaDB 11.4.7, State Machine Adapter symfony_workflow
  • GitHub Check: End-to-end tests (MariaDB) / Non-JS, PHP 8.4, Symfony ^7.3, MariaDB 11.4.7, State Machine Adapter symfony_workflow, ApiPlatform ~4.1.7
🔇 Additional comments (2)
features/admin/product/managing_products/browsing_products_with_main_taxon_without_name.feature (1)

1-19: New Behat feature accurately covers the regression scenario

Background and scenario setup look correct: they reproduce a product with a main taxon whose name is empty in the admin locale and assert that the product list still renders. This is a good, focused coverage of the reported bug with consistent step wording and tags.

src/Sylius/Behat/Context/Setup/TaxonomyContext.php (1)

149-157: Step definition is consistent and mirrors existing taxonomy locale handling

The new @Given step’s regex matches the feature text, and the implementation aligns with existing patterns in this context:

  • Locale capture uses the same ("... locale") convention as theStoreHasTaxonomyNamedInAndIn, so $localeCode should receive the normalized locale string used as a translation key.
  • Mutating the translation via $taxon->getTranslation($localeCode)->setName('') and then just calling flush() is consistent with other methods here that tweak an already-managed TaxonInterface (theTaxonIsEnabled / theTaxonIsDisabled), so the change should be persisted as long as the taxon is managed when the step runs.

Please just confirm that this step is only ever used with taxons that have already been persisted (which seems to be the case in the new feature), in which case this implementation is solid.

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 21, 2025

❌ Preview Environment deleted from Bunnyshell

Available commands:

  • 🚀 /bns:deploy to redeploy the environment

@TheMilek TheMilek merged commit ac5cb34 into Sylius:2.1 Jan 20, 2026
48 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Admin AdminBundle related issues and PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2.0] An error occurred during rendering the "data_table" hook in the "sylius_admin.common.index.content.grid" hookable.

2 participants