As you can see from the title, I am using Views to display products from the Commerce module. Each "product" is a download, which required a download field. Upon first install, I re-used the publicly-available "upload" field on the Commerce product (not the node). Built the views to follow the "Tie to Product" relationship and everything worked great.
Now it seems that I may need to restrict access to some of the downloads. I removed the "upload" field and replaced it with a "private" file field. This causes the following errors every time that I access the view as a page, or when saving:
Notice: Undefined index: commerce_product in views_handler_field_field->access() (line 78 of [local-path]/sites/all/modules/views/modules/field/views_handler_field_field.inc).
Notice: Undefined index: commerce_product in views_handler_field_field->access() (line 78 of [local-path]/sites/all/modules/views/modules/field/views_handler_field_field.inc).
I have tried removing the Views relationship and recreating it. That does not seem to help, so for now I am covering up the error messages by re-adding "upload" field to the Commerce product.
Any ideas how to correct the view's dependence on this field? The row format is "grid" so there is no selected use of the "upload" field.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 1477054.patch | 687 bytes | dawehner |
Comments
Comment #1
dawehnerIt's somehow an interesting question why commerce_product is not added to the entity_tables defined there.
This patch fixes the issue, though this doesn't allow to understand the original issue and it's definitive a bit slower.
Comment #2
tim.plunkettCan you provide an exported view to test this with? Paste it in on http://paste.pocoo.org and copy a link here.
I've tried to reproduce as best I can, but I can't. Clean install of commerce, it worked fine.
field_views_field_default_views_data()adds this information in, and I see no reason it would break like this.Also,
views_handler_field_field::query()uses this same pattern, so if there was a real reason for this,$this->definition['entity_tables']should just be abandoned altogether.Comment #3
johhan commentedHi,
on page with View definition (the "SQLSTATE..." is down on the page):
Notice: Undefined index: commerce_product ve funkci views_handler_field_field->access() (řádek: 78 v souboru D:\drupal\www\sites\all\modules\views\modules\field\views_handler_field_field.inc).
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS commerce_product_, '' AS field_data_commerce_product__entity_type FROM vp_co' at line 1
and on page with View:
Notice: Undefined index: commerce_product ve funkci views_handler_field_field->access() (řádek: 78 v souboru D:\drupal\www\sites\all\modules\views\modules\field\views_handler_field_field.inc).
Notice: Undefined index: commerce_product ve funkci views_handler_field_field->query() (řádek: 134 v souboru D:\drupal\www\sites\all\modules\views\modules\field\views_handler_field_field.inc).
Notice: Undefined index: entity keys ve funkci views_handler_field_field->query() (řádek: 146 v souboru D:\drupal\www\sites\all\modules\views\modules\field\views_handler_field_field.inc).
This error messages started after adding "Commerce Line item: Product" field into Field(s) part of the View definition.
This View exported here:
http://paste.pocoo.org/show/587441/
Thank you
John
P.S. Patch 1477054.patch not tried for now
Comment #4
uking commentedI got the same error and patch the function access() and query() with success.
In function query () there is this addional change necessary
$base_table_data = views_fetch_data($base_table);to
$base_table_data = views_fetch_data($this->base_table);Comment #5
dawehner@johhan Sorry pocoo is dead :(
@uking
Would you like to redo the patch, based on your change?
Comment #6
nmc commentedI have the same issue. Here is the View export available at http://pastebin.com/P2qza7Ys
Applying patch #1 fixes the errors of:
Notice: Undefined index: commerce_product in views_handler_field_field->access() (line 78 of [local-path]/sites/all/modules/views/modules/field/views_handler_field_field.inc).But SQL error remains:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS commerce_product_field_data_commerce_product_, 'commerce_product' AS field_da' at line 1Comment #7
dydave commentedHi guys,
I had the exact same error after updating views from 3.3 to 3.5.
Right after running the update.php (which actually did nothing, btw, but just in case), prompted the error message from this post (Notice/Warning).
I went in the module as indicated by the warning and did a:
if (!isset($this->definition['entity_tables'][$base_table])) dpm($this);
[/views/modules/field/views_handler_field_field.inc around line 127]
which allowed me to trace down the view name, display and *problematic field*.
Then I went in the corresponding view/display, removed the field and added it again exactly as it was before (default config, actually), then finally saved.
It seems this was enough to make the warning go away and after flushing cache or running update.php again, there is no more notice/error like this one.
I would assume that there was some bad/deprecated/old/corrupt data in my views and removing/adding/saving did the trick in this case.
However, I haven't investigated exactly what could be the cause of the problem and would be interested to know if anyone figures this out.
I hope this comment will help others that would encounter the same issue as we did.
Feel free to let me know what you think about this approach and I would be glad to hear if you would have any other recommendations or advice.
Thanks in advance.
Comment #8
Lars Bo Jensen commentedThank you for your post, DYdave, it was informative. I got the issue after deleting the field_image from a product type. I added it again, and everything seems fine. Ca it be related to this (old) issue: http://drupal.org/node/1265152 ?
Comment #9
dydave commentedThanks a lot for your reply Lars and the track you suggested.
Let's see if we can get other developers in the Drupal Commerce tracker involved.
I have posted a ticket at: http://drupal.org/node/1802924 with a quick summary of links to this ticket.
Perhaps we'll mark new ticket as duplicate and move this ticket over to Drupal Commerce tracker. First, let's see what developers have to say about this new ticket and if anyone is interested in working on that.
Until then, I guess we'll have to use some kind of workaround as suggested in this ticket.
Any further feedback would be greatly appreciated.
Thanks in advance.
Comment #10
summit commentedHi,
I tried all this in this thread but I have still:
This happens when I make a relation between a content: referenced product and the product within the showing of the field.
Greetings, Martijn
Comment #11
dydave commentedHi @Summit,
Did you try the approach suggested in #7, removing and adding the field again?
Try to remove the product reference field and the relationship, then save the view, then add them again exactly as they were before and try saving again.
Have you tested that already?
Thanks in advance for your reporting, testing and comments.
Cheers!
Comment #12
summit commentedHi,
I tried all that, but adding this field: (Product) Content: Product reference with relation Content: Products.
I got these errors.
Greetings, Martijn
Comment #13
dydave commented@Summit:
Thanks again for your prompt feedback.
Just a quick thing to confirm:
Did you make sure you flushed the cache also after/during doing all this?
Could you maybe try again and flush the cache?
Otherwise:
Ideally, it would be great if you could do some debugging with devel:
Have you tried:
On top of that, it would really help if you could also paste here (with some formatting) the debug backtrace from Commerce Devel (just need to install/enable the module and the backtrace can easily be copied from the Recent log messages detail view of the error log message).
Based on that we could perhaps give you further guidance on how to place more traces in the code.
Otherwise it could be quite cumbersome (for all of us) to help you on this, since we would need to be able to reproduce the issue entirely on our local environments which would mean that we would need all your modules versions, plus all the objects/fields/views that would be defined on your site (to be able to touch the code and debug/backtrace/trace down quickly)....
Any additional help, comments, feedback, advice, suggestions, recommendations, questions or issues would certainly be highly appreciated.
Thanks very much to all in advance for your comments, suggestions and testing.
Cheers!
Comment #14
summit commentedHi, Will try to do this tomorrow, otherwise it stalls a week because EasternHolidays!
greetings, Martijn
Comment #15
summit commentedHi,
I know which field it is: (Product) Content: Product reference
Devel and Commerce Devel logging gave me:
Thanks for helping me!
Greetings, Martijn
Comment #16
rszrama commentedI'm not sure this is an issue with Commerce - it may just be some very oddly constructed Views. ; )
I tested with the one linked in comment #6, and the problem was with adding a field to render the product reference field of a line item as an Add to Cart form - but riddle me this... why in the world would you ever do that? Especially when the View in question already has a relationship directly to the product?
And let's just look at the purpose of this View... well, no, I can't even divine it:
And all that just to show a set of products with Add to Cart forms. The relationship to line items was completely unnecessary, and if the goal was to only turn up products that have been added to orders (perhaps owned by the viewer), then you would just start with a base table of line items (or even orders!) and join from there through to the product displays.
In other words: the relationships on this are screwed up.
Now, that said, the code is allowing people to go crazy by defining a relationship from the product table to "Commerce Line item: Referenced product", ostensibly because there's a product reference field that comes by default on all product line item types. However, it should only be showing a reverse relationship if anything (line items referencing the product), not a relationship from the product to the line item through the product reference field.
This relationship should not exist. The reason we're getting errors with missing base tables is the LEFT table isn't known to the relationship in the context it's being used. Whoops.
What I don't know is what exactly this code should be doing differently:
Somehow this code results in the relationship from the line item's product reference field being available when the base table of the View (or a joined in table) is commerce_product. Here's the final data array:
If anything sticks out in here, lemme know. fwiw, this loop looks to have come from the taxonomy term reference field code, which uses a similar loop:
Funny enough, that bit where it adds "the relationship only on the tid field." gets executed twice. ; )
Comment #17
rszrama commentedAlso, here's a much simpler View to test with that requires no additional fields:
Comment #18
madelyncruz commented#1 fixed the issue I have right now. Thank you!!!
Comment #19
darrellduane commentedThe patch in issue https://www.drupal.org/node/2331209 will likely fix the error on line 127 listed in #7, #10, #13.
Comment #20
argiepiano commentedThe approach in #7 helped me figure out the problematic view and field. Thanks @DYdave
Comment #21
zalak.addweb commentedComment #22
riddhi.addweb commented