Problem/Motivation

While working on the customers and address migration, I came across the issue where there might not be a Drupal user corresponding to the profile being imported. The preSave() function makes a call to the loadByUser() which expects the user object to be passed. For this particular scenario, the user does not exist yet. This might not be a generic scenario - so not marking this as a bug.

Proposed resolution

Check if the account exists.

Remaining tasks

Create a patch. Review.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

AjitS created an issue. See original summary.

ajits’s picture

StatusFileSize
new876 bytes
ajits’s picture

Status: Active » Needs review
ajits’s picture

ajits’s picture

Issue tags: +Needs reroll

The patch is no longer applicable.

bojanz’s picture

Status: Needs review » Needs work

Updating status. There's also postSave() to think about.

neelam_wadhwani’s picture

StatusFileSize
new1.65 KB
new3.06 KB

Hello,

For current profile check in postsave() and assigned it as default for current profile.
Attach is patch.

neelam_wadhwani’s picture

Status: Needs work » Needs review
abramm’s picture

Status: Needs review » Needs work

This is actually a bug since this code in preSave checks for profile owner existence by calling getOwnerId() and assuming that getOwner() would return non-null value as well:

    // Mark the profile as default if there's no other default.
    if ($this->getOwnerId() && $this->isPublished() && !$this->isDefault()) {
      $profile = $storage->loadByUser($this->getOwner(), $this->bundle());
      if (!$profile || !$profile->isDefault()) {
        $this->setDefault(TRUE);
      }
    }

However, this is not the case since getOwnerId() returns an ID of referenced user which may not exist (i.e. the user was deleted).
On the other hand, getOwnerId() may return 0 (meaning user is anonymous) so the correct approach would be checking both getOwnerId() (i.e. profile references some non-anonymous user) and getOwner() (profile references existing user).

abramm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new847 bytes
new1.68 KB

Unfortunately I don't have working PHPUnit environment at the moment so I've added test changes relying on Drupal.org CI.

Attaching two patches, one having test only (expected to fail, demonstrates the bug) and the second one with test + fix.

The last submitted patch, 10: 3080025-10-test-only-failure-expected.patch, failed testing. View results

abramm’s picture

Category: Task » Bug report
keerthana13’s picture

StatusFileSize
new2.24 KB

Getting null in loadMultipleByUser() as well. so rerolled patch #10

abramm’s picture

Hi @keerthana13 ,
Can you please post an interdiff as well as two patches (test only which should fail and test+fix which should pass)?

That would help adopting the patch.
Thanks!

  • jsacksick committed acedd50 on 8.x-1.x
    Issue #3080025 by abramm, neelam_wadhwani, AjitS, keerthana13, bojanz,...
jsacksick’s picture

Status: Needs review » Fixed

Committed the patch from #13, thanks everyone!

  • jsacksick committed dfbf75a on 8.x-1.x
    Issue #3080025 followup: Put back the getOwnerId() check in Profile::...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.