Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Steps to reproduce:
- Install Drupal using the standard profile.
- Add a text field to articles.
- Create at least one article and one basic page.
- Create a view that shows all content, and displays fields. Add the text field you created above as one of the fields in the view.
- Turn on aggregation for the view. The result is you get an AJAX error while editing the view, and a whitescreen when accessing the view after it is saved: "Fatal error: Cannot access empty property in field.attach.inc on line 325".
I believe this is mostly a bug in Drupal core - see #1161708: Problem with function _field_invoke when used on a content type with no field instance. However, I started working on this as a Views bug before I realized that. Plus, it makes sense to have an issue for it in the Views queue since that's where people will find it.
I think it is possible to patch Views to fix it; I'm attaching the patch I worked on before I came across the core bug. This patch seems to work, but probably not worth applying it to Views unless the core bug doesn't get fixed soon.
Comment | File | Size | Author |
---|---|---|---|
views-aggregation-missing-field.patch | 781 bytes | David_Rothstein | |
Comments
Comment #1
David_Rothstein CreditAttribution: David_Rothstein commentedComment #2
dawehnerOh wow this totally makes sense, things can be quite easy somtimes.
First i thought this is related to http://drupal.org/node/1417520 but it's not.
A comment would be really helpful here. What kind of "edge" cases can appear. At least for the one you added it's actual a real logical and reproducable reason.
Comment #3
Yuri CreditAttribution: Yuri commentedThis fatal error is still happening.
Comment #4
Pimmy CreditAttribution: Pimmy commentedSame here: For me it happens when I try to aggregate on fields which do not have value.
I've been struggling with this about a year ago and eventually managed to work around this bug by adding default value of 0 (zero) to all fields participating in the view.
Now however I cannot do this due to complexity with 'Field Collections' and other content, so I would really need help with fixing this.
Thanks,
Pimmy
Comment #5
karangi CreditAttribution: karangi commentedI narrowed it down to a view that always gave the following ajax pop up error:
So I removed and redid the view and it solved the problem.
Comment #6
Pimmy CreditAttribution: Pimmy commentedpatch makes the error disappear, but aggregation still fails to work for columns containing empty results.
See example: http://drupal.org/node/1451894
redoing the view makes no difference.
Comment #7
joerch CreditAttribution: joerch commentedSame problem with a commerce-kickstart installation.
Glad to know a little more about the problem now.
Seems to be the same here. Need to review this.
Comment #8
dkdnt CreditAttribution: dkdnt commentedI have this error disabled aggregation in views (D7.19)
and that when I refresh other site or add content:
patch not help :/
These errors pop up when printing field and displays the node does not contain the field.
This code in the page.tpl.php makes these errors:
but this will avoid page--node-type-with-field_name.tpl.php
sorry for my English;)
Comment #9
JMOmandown CreditAttribution: JMOmandown commentedNot that it is specific to this module, but back to David_Rothstein's point. This is not a bug inherent to views, we experience this on a production site with the commerce module when trying to pass information to another entity that is using the same field as an existing field (another field instance).
Comment #10
GemVinny CreditAttribution: GemVinny commentedI am also getting the same issue, redoing the view didn't fix it for me either.
Has anyone had any joy?
Thanks
Gem
Comment #11
GemVinny CreditAttribution: GemVinny commentedI worked out what my issue was!
I didn't set the filter criteria to the content type so it was bringing back all content types. Obviously this is going to cause issues because it's bring back text as well as numbers...
So I just disabled Aggregation added in the filter criteria to filter only that content type, enabled aggregation and it worked.
Hopefully this will help someone else.
Gem
Comment #12
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks David_Rothstein, you're a hero. The patch attached to the original posting works like a charm.
Applies for views with different content types and aggregation and usage of a field which is not part of all involved content types... very specific case... the more thankful I am about your patch! :)
Comment #13
David_Rothstein CreditAttribution: David_Rothstein commentedThank you, @Shnapoo! Glad it helped.
Hopefully the root cause (#1161708: Problem with function _field_invoke when used on a content type with no field instance) can be fixed in Drupal core too.
Comment #14
Sabareesh CreditAttribution: Sabareesh commented@David_Rothstein : Your path works well and solves this issue. Great work David_Rothstein!
Comment #15
Sabareesh CreditAttribution: Sabareesh commentedBased on #12 and my own experience I am closing this issue.
Comment #16
David_Rothstein CreditAttribution: David_Rothstein commentedThanks, @Sabareesh. But this patch hasn't been committed yet as far as I know, so the issue should remain open.
Comment #17
Sabareesh CreditAttribution: Sabareesh commented@David_Rothstein : Yeah I forgot that and closed this ticket, but thanks again for your work!
Comment #18
Exploratus CreditAttribution: Exploratus commentedWorked for me. Thanks!
Comment #19
femtox77 CreditAttribution: femtox77 commented@David_Rothstein : Worked for me. Thanks!
Comment #20
neorg CreditAttribution: neorg commentedThanks @David_Rothstein
Patch in original pors worked for me.
Problem occurred on MERCI module https://drupal.org/project/MERCI White Screen of Dead ( WSOD )
Error in apache log:
PHP Fatal error: Cannot access empty property in /var/www/[DOMAINNAME]/html/modules/field/field.attach.inc on line 324
Drupal core: 7.23
Views: 7.x-3.7
I really wonder why this patch isn't still committed in the Views module.
Comment #21
dawehnerAdded a line of documentation for myself and committed the initial patch.
Drupal 8 looks way different so this don't have to be ported.
Comment #23
rudiedirkx CreditAttribution: rudiedirkx commentedThis is not a Views bug. It's a bug in _field_invoke_get_instances() that doesn't check if the field exists in the bundle, so the results is sometimes
array(NULL)
, which is obviously incorrect. Adding anarray_filter()
fixes the problem, in the right place, not in Views.but that's core, so that's never gonna change...
Comment #24
David_Rothstein CreditAttribution: David_Rothstein commentedYes, this is a core bug - see #1161708: Problem with function _field_invoke when used on a content type with no field instance which I linked to in the original issue report.
Comment #25
rudiedirkx CreditAttribution: rudiedirkx commentedOh wow I completely missed that. My bad. I created a core bug that I'll now close.
Comment #26
more770 CreditAttribution: more770 commentedI have the same error, but I can't solve it with David_Rothstein patch.
Any other solution?
I'm using Drupal 7.21