Needs review
Project:
Simplenews
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
24 May 2013 at 07:21 UTC
Updated:
15 Jul 2014 at 22:58 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
sumeet.pareek commentedI have the exact same errors but with different line numbers as seen below
I hope I will get to investigating this bug and if a solution comes up then submit a patch too, but right now I am chasing deadlines and have a HUGE mass unsubscription to do. I am doing the SQL query route, pulling out the `snids` from the emails and then deleting their records from `simplenews_subscription` table for now.
My setup details that might help find the bug below.
Comment #2
berdirDon't see how this would be possible, that sound like you have categories that are displayed and selected for unsubscribe but then don't exist anymore.
Please check your newsletters and their id's, do they match the id's in those error messages? Do you have terms in the simplenews vocabulary that aren't listed as a newsletter?
Comment #3
jking1224 commentedI agree with the original post. The line numbers may change, perhaps due to different revisions of code. I believe the problem is that when you attempt to "mass un-subscribe" an email address from a list, to which the email is not currently subscribed, you get this out of range index error.
I commonly check ALL the lists when I am un-subscribing someone. I wish to remove them from all my lists, not just the ones I know they belong to. So, if the email is not already subscribed to a specific list, then shouldn't get an error, just skip the item and move on.
Comment #4
miroslavbanov commentedThe call to
simplenews_categories_load_multiple()is supposed to only cache when called to get all categories, but it's really not. Here is a patch to fix that. But in reality, I think the cache should be removed from that function.Comment #5
rliThe patch in #4 works for me. Thanks.
Comment #6
miro_dietikerI agree that the patch makes sense.
If simplenews_categories_load_multiple() currently receives $tids or $conditions, ... then the static categories cache is overwritten. The next call of the function without condition results in lack of all other $tids.
However, we need test coverage for this ugly bug.
Test location to adapt/extend (and reproduce the bug) is simplenews.test line 1446+.
Comment #7
miroslavbanov commentedWould it be better if we cache and retrieve from cache in every case?
I was thinking that I can
serialize()orjson_encode()the query parameters, and use them as cache key.Comment #8
miro_dietikerI doubt it's worth doing this as it's only a static cache, not a persistent one.
This is not a common pattern in Drupal yet.
It depends the loop for mass imports. (I didn't check the exact code calls. That's why i ask for a test. It's very easy then to output the function calls with debug().) If it currently really triggers N times an uncached lookup we could investigate if it's worth getting rid of this query.
Comment #9
Anushka-mp commentedHere is a patch to test that the 'categories_load_fix_cache-2002584-4.patch' (Comment #4) works fine and solves the issues on mass unsubscribe.
Comment #10
miro_dietikerPlease set it to "Needs review" when submitting a patch so the testbots will test it.
And regarding type, it's still a bug report, even if it will be fixed. :-)
Comment #12
Anushka-mp commentedHere is the patch I've created before the one I uploaded in the comment #9. With this patch, local tests passes without any issues. I will review the earlier patch and fix the bugs.
Comment #13
Anushka-mp commentedHere is the patch I've created before the one I uploaded in the comment #9. With this patch, local tests passes without any issues. I will review the earlier patch and fix the bugs.
Comment #15
berdirSo the patch now proves that it fails. Now we need a combined patch with the test and the fix that should then pass.
(Mostly) coding style review below:
Make sure to check with the drupal coding standards. opening "{" for classes and methods should be on the same line as the class/method.
It is no longer necessary to use t() here, just provide the string directly. Also no need to specify the patch.
I assume you copied this because this seems unnecessary, we are not using that function or using the block module.
Comments should always have an empty space after the // and end with a ".".
There is a lot of code here to replicate the strange behavior of the confirmation message, which repeats the e-mails in a weird way.
It might be easier to fix the code that prints the e-mails to make them unique (with an array_unique() or so) and then we can simplify the logic here to a single line more or less (create array of e-mails, then implode() into a string.
It looks like you have this code twice here?
The drupalLogout() is not necessary, because the test is executed in a isolated enviroment that is completely deleted when you are done. You only need logout when switching the user in the same test.
Comment #16
Anushka-mp commentedHere is the patch including fix for the mass unsubscribe (comment #4) and the test for testing it(Comment #12).
Comment #17
miro_dietikerReverting issue summary.