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.
Problem
field_views_field_default_views_data()
tries to register views data for entities that do not have a base table.
Steps to reproduce
- Enable Contact module.
- Enable Views module.
Comment | File | Size | Author |
---|---|---|---|
#24 | 1867572-24.patch | 3.21 KB | damiankloip |
#24 | interdiff.txt | 670 bytes | damiankloip |
#20 | drupal-1867572-20.patch | 3.22 KB | dawehner |
#20 | interdiff.txt | 859 bytes | dawehner |
#17 | drupal-1867572-tests-only.patch | 1.89 KB | dawehner |
Comments
Comment #1
dawehnerOh i see contact messages aren't actually stored at all, but they are fieldable.
Wouldn't it make maybe more sense to check whether the entity has a storage engine and this engine extends the database?
Comment #2
dawehnerOn the longrun we probably want to have a MemoryStorageController.
Here comes a test + the patch and test.
Comment #4
dawehner#2: drupal-1867572-2.patch queued for re-testing.
Comment #5
damiankloip CreditAttribution: damiankloip commentedWhatever contact module is up, it seems a bit wrong anyway. This fix works fine, and has tests. Ideally it wouldn't be needed but meh :/
This might need to be re rolled for the new field api changes?
Comment #6
dawehner#2: drupal-1867572-2.patch queued for re-testing.
Comment #8
dawehner#2: drupal-1867572-2.patch queued for re-testing.
Comment #10
swentel CreditAttribution: swentel commentedThis should fix it
Comment #11
dawehnerWe could save some time my not calling ->get() without some arguments.
Comment #12
damiankloip CreditAttribution: damiankloip commentedYep, why not. Many savings of time will lead to lots of time eventually :)
Comment #13
olli CreditAttribution: olli commentedShould we pass the table, not field name?
Comment #14
damiankloip CreditAttribution: damiankloip commentedGood spot. We do need to prefix the field name, yes. Otherwise we return ALL the data. SO the test at the moment is actually a false pass :) Let's add a test to check we have the expected data array back aswell, or is that too much?
I think yched had a really good point a little while ago that views_data returns everything if a key isn't found.
Also, did you check out the tests from #2, the exceptions are right I think, as they throw errors that initially were the problem trying to join on a non existent base table.
How about this? Interdiff is slightly wrong as I added too early, but you get the idea.
Comment #15
damiankloip CreditAttribution: damiankloip commentedWith a correct assertion message for the test too.
Comment #16
olli CreditAttribution: olli commentedGreat, thanks. I dont know if checking the keys is too much.
Comment #17
dawehnerGood points, here are new versions of the actual patch/test only.
Comment #18
damiankloip CreditAttribution: damiankloip commentedI also just created this related issue: #1880834: Don't return all data from views_data service when an invalid table is requested
Comment #19
olli CreditAttribution: olli commentedThat is even better. Could we roll #15 with it?
Comment #20
dawehnerSorry damian, I forgot to refresh the browser window before working on stuff.
This interdiff is between this patch and #15
Comment #21
damiankloip CreditAttribution: damiankloip commentedNo worries, looks good to me. I guess we might as well use the field helper function to get that.
Comment #22
jibranRTBC as per #19
Comment #24
damiankloip CreditAttribution: damiankloip commentedWe want to assign $this->field the return value of field_create_field, so we get all the defaults.
This should be good now.
Comment #25
dawehnerLooks good for me!
Comment #26
webchickCommitted and pushed to 8.x. Thanks!
Comment #27
sunMmm... why was this test added to Contact module?
Test coverage should always be added to the component/extension/code that exposes functionality and that is responsible for ensuring that its own functionality works as expected.
It's not Contact module's responsibility to test that Views operates correctly on entities that are not stored. Contact module really doesn't have any business with Views right now - like, none at all. ;)
Let's move this test over to Views' tests.
Also, we probably want to add an entity type to entity_test that doesn't have any storage, instead of adding a cross-test-dependency on Contact module. Just omitting the 'base_table' declaration in the entity type annotation should trigger the exact problem identically to Contact module's Message entity.
Comment #28
olli CreditAttribution: olli commentedGood point. Would it make any sense to move it to field module instead where the fix is, say Drupal\field\Tests\Views\ApiDataTest?
Comment #29
swentel CreditAttribution: swentel commentedThis is not a bug anymore. If someone wants to move go ahead.
Comment #44
quietone CreditAttribution: quietone at PreviousNext commentedThis was committed and re-open for follow up work. I've moved that to a new issue, #3270033: Move ContactFieldsTest.php to the views module and decouple it from contact module.
Therefore the fixed status from #26 can be restored as well as the Bug category.