Skip to content

[#291] Fixed 'EntityReferenceHandler' crash when entity label key is FALSE.#308

Merged
AlexSkrypnyk merged 1 commit intomasterfrom
feature/291-label-key-false
Apr 16, 2026
Merged

[#291] Fixed 'EntityReferenceHandler' crash when entity label key is FALSE.#308
AlexSkrypnyk merged 1 commit intomasterfrom
feature/291-label-key-false

Conversation

@AlexSkrypnyk
Copy link
Copy Markdown
Collaborator

Iterates on #292 by @khiminrm. Thank you for the contribution!

Summary

  • Fixed a fatal crash in EntityReferenceHandler::expand() when the referenced entity type has no label key (i.e., getKey('label') returns FALSE).
  • Entity types such as commerce_license do not define a label key, which previously caused an invalid orConditionGroup with an OR FALSE condition appended, crashing the entity query.
  • When $label_key is FALSE, the handler now falls back to a simple ID-only condition instead of building an orConditionGroup.

Problem

Entity types that return FALSE for getKey('label') triggered this code path:

$or = $query->orConditionGroup();
if ($is_numeric_id) {
  $or->condition($id_key, (int) $value);
}
$or->condition($label_key, $value);  // $label_key is FALSE - crashes
$query->condition($or);

Passing FALSE as a field name to $or->condition() caused a fatal error or an invalid query.

Fix

The query-building block is now guarded by a $label_key check:

if ($label_key) {
  $or = $query->orConditionGroup();
  if ($is_numeric_id) {
    $or->condition($id_key, (int) $value);
  }
  $or->condition($label_key, $value);
  $query->condition($or);
}
else {
  $query->condition($id_key, $value);
}

When $label_key is falsy, the handler matches by ID only, which is the only sensible fallback for entities with no label field.

Related

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 16, 2026

Warning

Rate limit exceeded

@AlexSkrypnyk has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 6 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 47 minutes and 6 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 59ca02dd-b795-4a31-a317-ef53efb1af3d

📥 Commits

Reviewing files that changed from the base of the PR and between d85cc50 and c4373bf.

📒 Files selected for processing (1)
  • src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/291-label-key-false

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.

@AlexSkrypnyk AlexSkrypnyk merged commit b36e272 into master Apr 16, 2026
6 checks passed
@AlexSkrypnyk AlexSkrypnyk deleted the feature/291-label-key-false branch April 16, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error in EntityReferenceHandler when $label_key is FALSE

2 participants