Notice: Undefined property: stdClass::$uid in profile_user_presave() (line 218 of /home/berdir/Projekte/d7/drupal/modules/profile/profile.module).

Getting this for every user when creating users with devel_generate. It looks like profile assumes that there is always a uid in presave, that is imho wrong.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Status: Active » Needs review
FileSize
550 bytes

Fix is simple.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, patch fixes the notice.

dhthwy’s picture

#1: profile_fix_notice.patch queued for re-testing.

Damien Tournoud’s picture

Status: Reviewed & tested by the community » Needs review

Is that the correct fix? Why was this moved to hook_user_presave() instead of hook_user_update()? Let's discuss.

Berdir’s picture

It's the correct fix *for the php notice* ;)

I guess it's a totally different story if the code is in the right place. It probably *was* before the $user->data changes so that the information doesn't end up in {users}.data but we can probably move it to update now..

Damien Tournoud’s picture

Status: Needs review » Needs work

Hm. Ok, so that was a misunderstanding somewhere during the refactoring of {users}.data.

Because the profile module doesn't need to add stuff to {users}.data, it doesn't need to implement hook_profile_presave().

Let's change that :)

effulgentsia’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs tests, +Needs backport to D7
+++ modules/profile/profile.module
@@ -215,7 +215,7 @@ function profile_block_view($delta = '') {
 function profile_user_presave(&$edit, $account, $category) {
-  if ($account->uid) {
+  if (isset($account->uid)) {
     profile_save_profile($edit, $account, $category);
   }
 }

This changes the logic to call profile_save_profile() if uid=0. If that's not desired, can we use !empty() instead? Also, let's add a test for this. For example, EntityCrudHookTestCase::testUserHooks() is one of several existing tests that invokes user_save() on a $account object missing a uid, and it would currently trigger this notice and therefore fail if profile.module were enabled during that test run.

Powered by Dreditor.

effulgentsia’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
1.71 KB
1.26 KB

Here's a patch that adds tests to demonstrate the bug (should fail), and another patch with the same tests plus the fix (should pass).

Because the profile module doesn't need to add stuff to {users}.data, it doesn't need to implement hook_profile_presave(). ... Let's change that :)

This patch doesn't change that, so that it can be backported to D7. Once it lands, this issue can be continued with a D8-only refactoring of hook implementations.

ParisLiakos’s picture

subscribe..
i know it is just a notice, but for d7 the isset patch should be fine :)

marcingy’s picture

Version: 8.x-dev » 7.x-dev
Issue tags: -Needs backport to D7

Profile no longer exists in d8.

rickmanelius’s picture

So does the patch in #8 need to be re-rolled? The main part looks like a simple one-line change. Anyone test yet?

Berdir’s picture

#8: profile-crudtests-withfix.patch queued for re-testing.

sah62’s picture

I just ran into this same error in d7 when the Ubercart module creates a new user account as part of the purchase payment process. I've implemented the patch in #8 for now.

daroz’s picture

Patch in #8 working here

rickmanelius’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed patch #8 works as well. Given #13, #14, and now #15 all work. Marking RBTC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Normally we'd need some actual assertions here to pass the "core worthy" test. However, given that this module's been removed from 8.x, this seems adequate for the purposes of catching this bug, and gives a base to build from in the future if needed.

Committed and pushed to 7.x. Thanks!

Status: Fixed » Closed (fixed)

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