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.

Files: 
CommentFileSizeAuthor
#8 profile-crudtests-testsonly.patch1.26 KBeffulgentsia
FAILED: [[SimpleTest]]: [MySQL] 33,562 pass(es), 0 fail(s), and 1 exception(es).
[ View ]
#8 profile-crudtests-withfix.patch1.71 KBeffulgentsia
PASSED: [[SimpleTest]]: [MySQL] 36,874 pass(es).
[ View ]
#1 profile_fix_notice.patch550 bytesBerdir
PASSED: [[SimpleTest]]: [MySQL] 22,471 pass(es).
[ View ]

Comments

Status:Active» Needs review
StatusFileSize
new550 bytes
PASSED: [[SimpleTest]]: [MySQL] 22,471 pass(es).
[ View ]

Fix is simple.

Status:Needs review» Reviewed & tested by the community

Looks good, patch fixes the notice.

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

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.

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..

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 :)

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.

Status:Needs work» Needs review
Issue tags:-Needs tests
StatusFileSize
new1.71 KB
PASSED: [[SimpleTest]]: [MySQL] 36,874 pass(es).
[ View ]
new1.26 KB
FAILED: [[SimpleTest]]: [MySQL] 33,562 pass(es), 0 fail(s), and 1 exception(es).
[ View ]

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.

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

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

Profile no longer exists in d8.

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

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

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.

Patch in #8 working here

Status:Needs review» Reviewed & tested by the community

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

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.