- Open on Drupal.org βCore: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass - πΊπ¦Ukraine artem_sylchuk Lutsk
Attempted to re-roll the patch as it doesn't apply to the dev version anymore
- πΊπΈUnited States tr Cascadia
This still absolutely needs a test case to demonstrate the error and prove the fix.
The last submitted patch, 24: votingapi_widgets-getresults-2990032-24.patch, failed testing. View results β
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.- πΊπΈUnited States loze Los Angeles
Yes I have been using this patch on 2.0.x-dev for some time, and it works well.
- Merge request !19Resolve #2990032 getResults is not returning the correct results β (Open) created by loze
- πΊπΈUnited States loze Los Angeles
Here is a MR for 2.0.x
@TR Mentioned that this needs a test to demonstrate the error and prove the fix. I unfortunately, don't know how to go about doing that.
But you can see my comment #11 for a description of two scenarios where it is failing for me.
These changes do resolve the issue for me and I have been using in production for some time now.
- πΊπΈUnited States loze Los Angeles
I've made some updates to the MR.
I was noticing some issues with incorrect vote results appearing when multiple vote fields were on the same page.
There was also some code duplication with a getResults() method in both the base form and the base widget classes so I consolidated those and and was able simplify and lean up the logic.
This seems to be working well at first pass.
- πΊπΈUnited States tr Cascadia
I think this is all good, but I really need a test case for this. I can write it if you can write down the specific steps needed to cause this error. I need to know how to set up the site - how to set up the fields/bundles/content types, then what actions have to be taken to get the wrong result and where does the wrong result show up? Do this for both of your cases mentioned in #11.
- πΊπΈUnited States loze Los Angeles
Thanks @tr. I agree on the need for test and wish I was able to figure that out myself.
Here are the steps as I see them.
To summarize: The
getResults
method in VotingAPI widgets returns incorrect results in certain cases due to how it combines records based on field names without considering entity types or distinct field names within the same entity.I have observed two specific cases where this occurs, though there may be others.
Steps to Reproduce
1. Fields with the Same Name on Different Entity Types
- Create a NODE type "page" and add a VotingAPI field named
field_rating
. - Create a MEDIA type "image" and add a VotingAPI field named
field_rating
. - Cast votes on both entities.
- Retrieve results for one of them. you can either look on screen, or programtically get them with the getResults() method
Expected Behavior:
Each entity type should have its own distinct vote results.Actual Behavior:
- The results are either combined incorrectly across entity types or otherwise inaccurate.
- Both the total votes cast and the average values are incorrect.
- This occurs because
getResults
groups records by field name without considering the entity type.
2. Two Fields with Similar Names on the Same Entity Type
- Create a NODE type "page".
- Add a VotingAPI field named
field_rating
. - Add a second VotingAPI field named
field_rating2
. - Cast votes on that node in both of the fields.
Expected Behavior:
Each field should return its own separate vote results.Actual Behavior:
- The results are incorrect due to the same underlying issue.
getResults
is searching for a substring of the field name so "field_rating" is also grabbing results from "field_rating2". - Both the total votes cast and the average values are incorrect.
I really wish I could set up a test for this myself. I spent time yesterday trying to figure out how to write a proper test but got lost on just the basics like creating a node and adding a votingapi_widgets field to it, let alone going about making it cast votes. So I appreciate any help or guidance on how to approach this.
- Create a NODE type "page" and add a VotingAPI field named