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
While trying to send a newsletter that is attached to the node, I get a huge list of notices telling that effort to get a property of non-object failed.
The symptoms are similar to #1739312: simplenews_send_source() results in PHP notices ("Trying to get property of non-object"), but definitely have another root, because the problem persists even in the latest dev.
Reason
That is so because I am trying to send a node, that existed before Simplenews module installation.
Solution
We need to create newsletter for each node existed before.
I will provide a patch soon.
Comments
Comment #1
PatchRanger CreditAttribution: PatchRanger commentedPlease review the patch.
Comment #2
BerdirThis does not scale. Imagine this is done on a node type with 10k or 100k nodes.
Instead, we should probably default to an empty/default newsletter object in case a node does not explicitly have one. We probable removed that due to refactoring but didn't think of that use case. To avoid this from happening again, we need to have tests for this. This will require a new test class which does not enable simplenews.module in setUp() but first creates a node, then uses module_enable() to enable simplenews and then attempt to send the newsletter.
Comment #3
PatchRanger CreditAttribution: PatchRanger commented@Berdir Thank you for detailed instructions.
I have created simpletest for this testcase - let's see how it will pass or not (in fact it should not).
Please review - make sure that this testcase really checks what we need to be checked.
It is my first simpletest ever created - so please be patient :)
Btw, I tried to follow your instructions as I have understood them (probably I have not) - as a result I had to do some refactoring of old testcases, hope you will appreciate it.
Comment #5
PatchRanger CreditAttribution: PatchRanger commentedHoorah! I didn't break anything!))
But it is time to make new testcase to work as designed.
Please review this one.
Comment #7
PatchRanger CreditAttribution: PatchRanger commentedOk, one more try.
Comment #9
PatchRanger CreditAttribution: PatchRanger commentedNumber of fails and exceptions is decreasing - but is not zero yet.
Somewhen it will.
Comment #11
PatchRanger CreditAttribution: PatchRanger commentedIs it normal that I'm debugging here - or there is a way to do it locally?
Comment #13
PatchRanger CreditAttribution: PatchRanger commented#11: simplenews-added_new_testcase-1780134-11.patch queued for re-testing.
Comment #14
BerdirYou can execute the tests locally, just enable Simpletest and then run the tests that failed on the testbot.
I haven't looked at the patch yet, but note that there can't be any API changes in 7.x-1.x as that version is stable now. So you either need to do it without changing the API or it can only happen in 7.x-2.x. Where #1309404: Convert Newsletter categories to custom entity is changing *a lot* and will be commited first. It might even partially solve this as a side effect.
Comment #16
PatchRanger CreditAttribution: PatchRanger commentedOh, thanks, you are just in time.
This patch contains only new testcase that you were talking about. No API changes, just some remaking of TestCase-classes.
It seems that I'm done with tests: now it's time to make the code that passing them.
Tests are necessary here in any case.
Comment #17
BerdirLooking at the patch, the problem is that you're are changing *a lot* that is not relevant to this issue in any way, like removing t()'s. See http://webchick.net/please-stop-eating-baby-kittens why this is a problem.
For example, a lot of your changes are going to conflict unecessarly with the linked issue, which means that you will have to re-do it for 7.x-2.x.
Also, changing the structure of tests is IMHO an API change too. Someone might have written a test (maybe in another contrib module) that relies on e.g. the simplenews test base class. A way to do it as an API *addition* instead of a change would e.g. be a second, optional argument that would not add simplenews. Or just not depend on the base class and copy some code instead.
Comment #18
PatchRanger CreditAttribution: PatchRanger commentedI see, thanks for your patience.
I am going to think about it for a while. For now I tend to re-roll it against 7.x-2.x (of course, splitting it to more relevant parts).
Comment #18.0
PatchRanger CreditAttribution: PatchRanger commentedFixed typo.