To reproduce:

  • Create a Paragraph bundle
  • Add paragraph field to a content type
  • Create node of content type and add a new Paragraph

Next, following notices pop up:

Notice: Undefined property: stdClass::$nid in entity_metadata_no_hook_node_access() (line 682 of /Users/xxx/Projects/drupal-7.39/sites/all/modules/entity/modules/callbacks.inc).

Notice: Undefined property: stdClass::$vid in entity_metadata_no_hook_node_access() (line 683 of /Users/xxx/Projects/drupal-7.39/sites/all/modules/entity/modules/callbacks.inc).

Notice: Trying to get property of non-object in entity_metadata_no_hook_node_access() (line 683 of /Users/xxx/Projects/drupal-7.39/sites/all/modules/entity/modules/callbacks.inc).

Notice: Undefined property: stdClass::$nid in node_access() (line 3005 of /Users/xxx/Projects/drupal-7.39/modules/node/node.module).

This only occurs during node creation (not during edit) because the nid/vid are not set yet at that point.

Comments

vollepeer created an issue. See original summary.

jeroen.b’s picture

Status: Active » Needs review
StatusFileSize
new1.4 KB

I'm sorry I got this into a release. We were in a hurry to bring out a security fix.
Does this patch fix it? It turns the $op into 'create' when the entity is new.

jeroen.b’s picture

StatusFileSize
new562 bytes

I thought of a simpler patch.

vollepeer’s picture

Great work, thanks for the quick feedback! Notices are gone, everything seems to be working well now.

  • jeroen.b committed a52cc37 on 7.x-1.x
    Issue #2562463 by jeroen.b: Parent entity access check throws PHP notice...
jeroen.b’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

rp7’s picture

Is it possible this issue is back again? Currently using latest dev.

rp7’s picture

Status: Closed (fixed) » Active
jeroen.b’s picture

@RaF7 can you tell me the line of the notice?

Sebastien VR’s picture

Notice: Undefined property: stdClass::$nid in node_access()

This notice is triggered during entity access check on line 285 of paragraphs.module.

if (entity_access($check_parent_op, $entity->hostEntityType(), $host_entity)) {
      $permissions[$account->uid][$cid][$op] = PARAGRAPHS_ITEM_ACCESS_ALLOW;
      $parent_permissions[$account->uid][$parent_cid][$check_parent_op] = PARAGRAPHS_ITEM_ACCESS_ALLOW;
    }

This happens when you add a new node that has to possibility to contain paragraphs.
During the paragraph item access check the host entity is being fetched as an object without a 'nid' while node_access() checks if the entity is an object or just a string (ex: node bundle)

$cid = is_object($node) ? $node->nid : $node;
jeroen.b’s picture

What version of the entity API are you using?

Sebastien VR’s picture

Hi Jeroen,

Currently i'm using entity-1.6

thomjjames’s picture

Hi,

Getting this issue too with paragraphy fields within a field_collection on a node:

node
- field_collection
-- paragraph 1
-- paragraph 2

Using Entity API: 1.6, Paragraph 7.x-1.0-rc4 & Field Collection 7.x-1.0-beta11.

Attached patch seems to fix it but not 100% sure of any access implications as I'm not so familiar with this module yet.

Cheers
Tom

socialnicheguru’s picture

Status: Active » Needs review

Just noting:

The fix in #5 is not in the present dev version of the module. I also acknowledge that may not be the most appropriate fix any longer

; Information added by Drupal.org packaging script on 2016-04-22
version = "7.x-1.0-rc4+1-dev"
core = "7.x"
project = "paragraphs"
datestamp = "1461369540"

Status: Needs review » Needs work

The last submitted patch, 14: paragraphs-fix-parent-access-2562463-14-7.x.patch, failed testing.

jeroen.b’s picture

That could be right. I totally rewrote the access checking because there were quite some issues with it.

@thomjjames, I'm currently trying to get the quality of the code up to par with the D8 version.
That mostly just means we need to add many tests to make sure we won't break anything.
Are you able to create a unit test for this? (and provide 2 patches: 1 with the fixed code + test, 1 with the test only. that way we can see the test actually confirms it is fixed now).

falco010’s picture

Thanks for patch #14, worked for me

opi’s picture

Same issue, with latest version of paragraphs (7.x-1.0-rc4) and entity API (7.x-1.8).

Patch from #14 works fine, but I can't tell if it's a good practice to set $host_entity to NULL.

sebastien m.’s picture

Status: Needs work » Needs review
StatusFileSize
new569 bytes

Put $host_entity to NULL is quite huge.
I think to set $host_entity->is_new = true should be enough and could do the job.

das-peter’s picture

Status: Needs review » Reviewed & tested by the community

Just stumbled over this issue too.
Patch looks good to me and solves the issue - so I'd say RTBC.

eelkeblok’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

See #17. We need to get some tests going to cover this.

lorenzs’s picture

StatusFileSize
new118.47 KB

When debugging I noticed the $hostEntity actually is a user object instead of a node? Of course this object does not have the 'is_new' property nor a nid...
Can anyone confirm that they also see a user as $hostEntity? This does not seem OK allthough I'm not familiar with this module's code.
But passing a user as 3th arg to entity_access is not correct and adding a 'is_new' to this object (patch #20) is not correct either allthough it fixes the warning...

screenshot debugger

lorenzs’s picture

Version: 7.x-1.0-rc2 » 7.x-1.0-rc4
Issue tags: +Needs security review

Still have this issue in rc4 with latest entity and entity API modules

xiaodoudou’s picture

Patch 14 doesnt really fix the issue.
By doing "$host_entity = NULL;" it will break the permission.

You have to do "$host_entity->is_new = true" like said on comment #20.

Thank you to @Sebastien @Actualys !

timme77’s picture

Patch in #20 is working for me!

idebr’s picture

@lorenzs #17: The values you are seeing are the default values added by the node module itself, see http://cgit.drupalcode.org/drupal/tree/modules/node/node.pages.inc?h=7.x...

@eelkeblok #22: What exactly do we need tests for? This issue is fixing a notice, not changing any APIs?

eelkeblok’s picture

That would be a question for @jeroen.b, I suppose. I was just relaying his request for tests from #17, I had not given the question on how exactly test for this condition any thought (ideally, we *should* be testing for this condition to not occur).

kumkum29’s picture

With the patch #20, it's ok for me !!!

pol’s picture

Status: Needs work » Reviewed & tested by the community

Patch in #20 fixed the issue. Thanks !

nicholasthompson’s picture

+1 on #20 too.. worked for me.

matthiasm11’s picture

#20 fixed the issue.

jstoller’s picture

Priority: Normal » Critical

I'm increasing the priority of this to critical, as it appears to fix an issue that is causing Paragraphs to fail all automated tests, thus holding up other issues in the queue.

emmanvazz’s picture

+1 on bumping priority on this as it is holding back other issues.

jeroen.b’s picture

Status: Reviewed & tested by the community » Fixed

This indeed does not need tests. Committed, thanks!

pol’s picture

Coool ! Thanks!

Status: Fixed » Closed (fixed)

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