GetDKAN / dkan

DKAN Open Data Portal
https://dkan.readthedocs.io/en/latest/index.html
GNU General Public License v2.0
365 stars 170 forks source link

Error when attaching resource to dataset... EntityMetadataWrapperException #3355

Open jtallantumich opened 3 years ago

jtallantumich commented 3 years ago

DKAN Install Profile (DKAN (dkan-7.x-1.17.1)) Production Site: https://mfield.umich.edu

Describe the bug

For about 3 months we've been unable to associate any resource to any dataset, regardless of how we try to make that association ("Add Resource" button in an existing dataset or referencing a resource from within the dataset edit page or relating it to dataset from the resource edit page) It always returns the same error message:

_EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. Value at node(17063)->og_group_ref: array ( '' => 'a:2:{s:8:"gravatar";i:1;s:17:"mimemailtextonly";i:0;}', ). in EntityDrupalWrapper->set() (line 756 of /var/www/html/profiles/dkan/modules/contrib/entity/includes/entity.wrapper.inc).

Bypassing the validation in the entity module listed in the error above by commenting it out will actually allow the resource to be added, and instead the log gets filled up with these two errors, the first one about 50 times:

_Notice: Trying to get property of non-object in dkan_dataset_get_dataset_groups() (line 669 of /var/www/html/profiles/dkan/modules/dkan/dkan_dataset/dkan_dataset.module).

Warning: Illegal offset type in OgBehaviorHandler->groupAudiencegetDiff() (line 163 of /var/www/html/profiles/dkan/modules/contrib/og/plugins/entityreference/behavior/OgBehaviorHandler.class.php)._

Disabling / re-enabling the 'DKAN Dataset Groups' module seems to fix the problem, but also breaks all of the many existing entity references that were entered before, on datasets and other content types.

Steps To Reproduce

I think this is probably only reproducable on our dev/production site... but can share with anyone who is able to dig into the problem.

Expected behavior

No errors when attempting to create a new dataset or adding a new resource to an existing dataset.

janette commented 3 years ago

@jtallantumich does the dataset you are adding the resource to have a value in the "Groups" field?

jtallantumich commented 3 years ago

@janette Thanks for looking into this. Yes, it does have a value in the "Groups" field. It autopopulates from the node editors designated group. image

janette commented 3 years ago

@jtallantumich is the person who is adding a resource to that dataset also in that group? or have the administrator role?

jtallantumich commented 3 years ago

@janette Yes and yes, I'm admin and part of that group

janette commented 3 years ago

Have you done any customizations @jtallantumich ? I'm not able to reproduce the error, you could try xdebug to see what value is being passed to https://git.drupalcode.org/project/rules/-/blob/7.x-2.x/includes/rules.state.inc#L735

jtallantumich commented 3 years ago

@janette I assume you mean modification of the dataset and resource content type. Yes, we've added new fields to incorporate the Ecological Metadata Standard (EML) and entity for related items in our site like bibliographic references, research sites, and affliated researchers.

jtallantumich commented 3 years ago

@janette We will test the xdebug and get back.

andyguzman commented 3 years ago

@janette I tried setting a breakpoint there but it seems that it never makes it to that point in the process for it to hit the breakpoint.

(I'm working with @jtallantumich on the same site - this isn't a problem with a separate DKAN install)

It seems it fails prior to that and xdebug basically gives the same error as the watchdog error @jtallantumich opened the issue with. The node id the error is referring to is the resource node.

Just prior to that in the call stack, it is at line 808 of /profiles/dkan/modules/dkan/dkan_dataset/dkan_dataset.module - $wrapper_resource->og_group_ref->set($resource_groups);

I don't think I was getting this every time, but now on my local environment I'm getting an exception in at line 76 of /profiles/dkan/modules/dkan/dkan_datastore/src/Resource.php - Exception: Invalid node type when I try to edit an existing dataset.

I don't know if that provides any more insight into the problem. Please let us know if there is anything else you can think of that we can check.

Have you done any customizations @jtallantumich ? I'm not able to reproduce the error, you could try xdebug to see what value is being passed to https://git.drupalcode.org/project/rules/-/blob/7.x-2.x/includes/rules.state.inc#L735

janette commented 3 years ago

I'm going to loop @dafeder in here, he has more experience with customized dataset fields on 7.x-1.x sites, he may recall the things to look out for. Also wondering if you would be interested in upgrading DKAN to 2.x.

jtallantumich commented 3 years ago

Thanks @andyguzman and @janette. I hope @dafeder has some insight. Yes it is a goal to migrate/upgrade to DKAN2, but I'm not there yet...