Test scenario 1:
- create a node with an entityreference to a file_entity (image)
- create a view of nodes with entityreference to file_entity
- Delete the file_entity by fid referenced in the above node
- view the view, you will get an array_flip error.
Solution:
apply the proposed patch, it will provide a useful message telling you what node id that is missing an item. So rather than a useless error message from core , views puts a helpful watchdog message with helpful information.
Another test:
create new view of nodes
Relationships
Comment: Last Comment
Content: Last comment author
Fields
Content: Title
(Last Comment) Comment: Author (Author)
in views result, for each row, error appears:
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 179 of /home/u5444/domains/medstream.krypton.vps-private.net/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 356 of /home/u5444/domains/medstream.krypton.vps-private.net/includes/entity.inc).
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | views-array_flip_missing_field_item-1511392-13.patch | 1.13 KB | dsutter |
| #5 | sql.txt | 3.33 KB | dgastudio |
| #2 | export.txt | 6.26 KB | dgastudio |
| #1 | last_author.view_.txt | 3.58 KB | dawehner |
Comments
Comment #1
dawehnerMh, as always i try to reproduce problems, so it's possible to fix them later.
Here is an export i tryed to play with, though i didn't got an error. What about providing an export for us? Maybe you text is missing one little detail here.
This kind of errors happens if $entity_load_multiple is called with wrong parameters.
Comment #2
dgastudio commentedsorry, attached the export.
also, can you please add comment author if comment is from not registered user?
i have imported your view, the result is the same
http://medstream.krypton.vps-private.net/testhh
Comment #3
dawehnerI'm wondering whether you have something like realname module installed? By just using this view i don't get an error like that, even every comment is created by uid = 0 etc.
Here is a short guess: your comment/node_comment_statistics table contains entries for a uid "" but actually it should be "0" so if something is triggering user_load, for example realname the notice get's fired.
It would be somehow helpful if you create a backtrace from that. Therefore you can use something like this code in "includes/entity.inc"
I hope this gives enough information to tell a bit more about this problem.
Comment #4
dgastudio commentedHi!
first of all, thank you for help me!
no, i don't have realname installed.
I have added your code to entity.inc. No result.
so, i have changed it to dprint_r($ids);
the result is:
http://medstream.krypton.vps-private.net/testhh
Comment #5
dgastudio commentedattached export of one of my comments from phpymadmin.
Comment #6
dgastudio commentedi think i have found the problem
i'm displaying, for example, 10 nodes in views.
5 nodes have comment (relationship "last comment" works)
but other 5, no, so, this is becouse id's array es empty and can't be flipped.
can you check it please?
thank you.
Comment #7
esmerel commentedComment #8
dsutter commentedI am getting
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 175 / Warning: array_key_exists() expects parameter 2 to be array, null given in theme_image_formatter() (line 615Solved with this patch, which throws a watchdog notice instead of trying to render the missing item.
Comment #9
dsutter commentedComment #10
joseph.olstadPatch 8 is really helpful, we were bouncing around this array_flip issue for months internally wondering where or how to fix this. Lo and behold, patch 8 to the rescue. Now our drupal admins will no longer have to scratch their heads with annoying array_flip errors caused by content with missing fields. Instead of an annoying and confusing , almost meaningless array_flip message, patch 8 prevents an array_flip by stopping the rendering process for empty field items. Rather than array_flip, a helpful watchdog message is provided that provides information about a node or entity that has a field with an empty or missing item. So now our drupal admins can solve the issue themselves by fixing the content that was causing the issue.
Great job @dsutter , 5 years after this issue was openned, you came up with an elegant solution! Great idea.
After reviewing the patch a bit more, we might want to add some validation for the entity_type first before assuming a node id (nid) and then add support for fid and mlid , tid , etc. Views can display many types of content more than just nid.
I'll see if I can whip up something to make this great patch even better.
Comment #11
joseph.olstadComment #12
joseph.olstadquick change so that all entity types are handled without notices. Not all entity types have nids
removed tab spacing , replaced with spaces
formatted for 80 columns as per code sniffer.
Comment #13
dsutter commentedUpdate to patch #12 to deal with yet another watchdog warning (array_key_exists() expects parameter 2 to be array).
Comment #14
joseph.olstadComment #15
joseph.olstadnew patch comming
Comment #17
joseph.olstadok, Duncans' patch 13 is the way to go.
we need to check that the array_key_exists because isset when the array element value is null would return false (meaning the test would fail) but we want to know when it's empty and empty on a null returns true
so therefore , logic stays as-is.
Comment #18
joseph.olstadComment #19
joseph.olstadComment #20
joseph.olstadComment #21
chris matthews commentedThe patch in #13 applied cleanly to the latest views 7.x-3.x-dev.