Problem/Motivation

ContentEntityBase::createDuplicate() erases the bundle value from ContentEntityBase::entityKeys, which causes infinite loops:

  1. ContentEntityBase::bundle()
  2. ContentEntityBase::getEntityKey()
  3. ContentEntityBase::getFieldDefinition()
  4. ContentEntityBase::getFieldDefinitions()
  5. ContentEntityBase::bundle()
  6. ...

Proposed resolution

Do not erase the bundle value when creating a duplicate. A similar check already exists in ContentEntityBase::onChange().

Remaining tasks

None.

User interface changes

None.

API changes

None.

Comments

xano’s picture

Status: Active » Needs review
StatusFileSize
new554 bytes

Xano queued 1: drupal_2326377_1.patch for re-testing.

berdir’s picture

That's unfortunate, can we add a simple assertion for this in an existing createDuplicate() test?

xano’s picture

I was already wondering why createDuplicate() did not have PHPUnit coverage, but now I remember that the reason this method is uncovered was that when I worked on adding the PHPUnit tests, we concluded that adding coverage for some methods would be too hard to do because of typed data.

What we can do is mock the typed data methods of the SUT and test that createDuplicate() calls those correctly. This prevents us from having to create crazy complex mocks. This has of course the usual drawbacks of mocking the SUT. What do you think?

berdir’s picture

Issue tags: +Needs tests

I'm not too sure about those kind of unit tests. There actually are some tests that mock the TypedDataManager there, but I'm not sure how useful it would really be (as in, being able to catch bugs). Just adding a single line assertEqual() in one of the existing kernel tests would at least be a lot easier to write.

berdir’s picture

Status: Needs review » Needs work

Needs work for tests.

xano’s picture

Status: Needs work » Needs review
StatusFileSize
new828 bytes
new1.35 KB
xano’s picture

Issue tags: -Needs tests
berdir’s picture

Status: Needs review » Reviewed & tested by the community

test-only patch would be good but looks good.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: drupal_2326377_7.patch, failed testing.

xano’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.31 KB

RTBC as per #9 if the tests pass.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I ran the test without the change in ContentEntityBase - it didn't fail. So back to needs work.

xano’s picture

Status: Needs work » Closed (works as designed)

I have no idea what changed since I first worked on this, but I removed the workaround from Payment in #2350593: Remove @todo in Payment::createDuplicate() and the problem no longer occurred.