This happens because of a change between 1.7 and 1.8 in modules/callbacks.inc, line 676:

<?php
$op = !empty($node->is_new) && $node->is_new ? 'create' : 'update';
?>

When a $node is being created, $node->is_new is not necessarily set, causing $op to become update instead of create.
This used to work in 1.7.

CommentFileSizeAuthor
#2 op_update_should_be_create-2807275-2.patch668 bytesanrikun

Comments

anrikun created an issue. See original summary.

anrikun’s picture

StatusFileSize
new668 bytes

Here is a patch.

anrikun’s picture

Status: Active » Needs review
anrikun’s picture

Issue summary: View changes
socialnicheguru’s picture

Status: Needs review » Reviewed & tested by the community

this seems to have worked for me.

webservant316’s picture

works for me.

howdytom’s picture

#2 op_update_should_be_create-2807275-2.patch works for me as well. Thank you.

emmanvazz’s picture

#2 works for me as well. Should be merged into the next version. Thanks!

marc.groth’s picture

Just confirming that #2 works for me too. Thanks @anrikun.

Hopefully this can be merged soon.

nvaken’s picture

Confirmed, works here too.

dasginganinja’s picture

Confirming that the patch in #2 functions as expected. I no longer experience these error messages.

idflood’s picture

Patch in #2 fixed the issue on one of our production website.

jstoller’s picture

#2 works for me too.

pol’s picture

Patch #2 is working.

kumkum29’s picture

#2 works for me too.

Entity API is a important module on a website. Patch this module is a bad thing...
Do you think include this correction in a next version of Entity Api?

knalstaaf’s picture

Version: 7.x-1.8 » 7.x-1.x-dev
jason_purdy’s picture

This patch works for me, too.

star-szr’s picture

Yes, the patch fixes the notice. Should this bug have an automated test added to try and prevent future regressions?

samt2497’s picture

Patch #2 is working for me.

delacosta456’s picture

hi on Drupal 7.53 patch 2 tested and applied successfully with both Phpstorm and Patch manager module.

vinmassaro’s picture

Ran into this issue with a node type that just contained a title field and one Paragraphs field. Patch works well, thanks!

jstoller’s picture

@Cottser: Maybe it's just me, but a test seems like overkill. How about a comment?

// We need to check if $node->nid is empty, since $node->is_new is not 
// necessarily set when a node is being created.
$op = empty($node->nid) || !empty($node->is_new) ? 'create' : 'update';
fago’s picture

Status: Reviewed & tested by the community » Fixed

Sure, good fix. Thanks!

  • fago committed d50db77 on 7.x-1.x authored by anrikun
    Issue #2807275 by anrikun: Notice : Undefined property: stdClass::$nid...
delacosta456’s picture

hi
Just for info after applying the patch, in case error still showing please do :

1- drush rr
2- drush cc all
3(once again) drush cc all
and refresh the page

You may not need to do all this in some environment .

..thanks

Status: Fixed » Closed (fixed)

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

giupenni’s picture

When in stable version?

pinueve’s picture

+1 #2, i applied patch on 7.x-1.8 v, thanks, also +1 #22, i have a custom access module and #22 also worked fine.

dercheffe’s picture

Is the patch committed to the stable version already?

sclsweb’s picture

dercheffe, no -- if I'm interpreting this correctly the current stable release is 7.x-1.8 released 22 September 2016, but the patch wasn't committed until way after that, 8 March 2017.

I would be very appreciative of a new stable release including this patch.

studiozut’s picture

The patch works until I reload the page, then the error returns. I cleared drupal cache and drush cache. I'm on Drupal 7.56, Entity API 1.8.

tlwatson’s picture

+1. This really needs to be in a stable release.

steven jones’s picture

This fix is included in Entity 7.x-1.9.