-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Regression] TypeError: filefield_paths_filefield_paths_process_file(): Argument #4 ($instance) must be of type array, null given #25
Comments
@bugfolder many thanks for reporting. Looking at function filefield_paths_filefield_paths_process_file()... in case instance is null, there must have been problems before. Just no fatal ones. This now just escalated with the type hint. I can see the problem, function field_info_instance() can return NULL, if the instance doesn't exist. ... But how in the world do you end up with |
I'll try to take a look tomorrow - attending a music conference at the moment and really swamped! |
Look at how
The last bit that gets |
Wow, now I get it (was a long day yesterday... 😉). Weird condition... (also in the D7 module), I don't get that logic. 🤔
Huh? |
I still don't get the logic of that condition, and decided to jump out of the loop before it. @bugfolder I never used Ubercart, so I'm relying on your testing here. If you have an idea for a reduced testing scenario in a functional test, I'd be happy to implement. 😉 |
TBH, this whole function filefield_paths_field_storage_pre_update() seems a bit odd. The entity is already known, so also the bundle via However, I'll suppress the impulse to refactor this ancient code. I simply don't know the module good enough (in depth). At least, this PR should make it slightly more robust. |
@bugfolder the inefficiency of that loop just bugged me too much, so I'd prefer a different approach. It should still prevent the error you saw, as the loop now only runs over actual field instances on this particular entity - can you confirm the fix? Other ideas? |
That seemed weird to me, too. The new PR fixes the problem in Ubercart, thanks! |
Oh, but I ran into something related. When running unrelated db updates after making this change, I got a lot of warnings of the form Warning: Trying to access array offset on value of type null in filefield_paths_field_storage_pre_update() (line 367 of /mysite/modules/contrib/filefield_paths/filefield_paths.module). Running out for a few hours, but I'll try to look into it further later today. |
Yes, please report any findings. Function field_info_field() can return null, but I wonder how that can happen, when we're looping over field instances... 🤔 Sounds weird. |
Maybe I have an idea... There's this core bug re Comment, where field instance files don't get deleted on Comment module uninstall... As this problem's not limited to that core module, it can happen, that some stale instance field config never got wiped out. At least, in theory something like that might be the case for your Backdrop install. @bugfolder do you also see nagging, when you go to /admin/config/development/configuration/single/export? That might verify my theory. Anyway, I updated my PR to also consider (leftover) instance config without field config. |
Using the previous PR (not your latest update), I narrowed down the warning to it happening during a "cache clear all" (which happens during an update, which is why I saw it there). So manually doing a "cache clear all" spews a whole slew of the warnings. Instrumenting the code to detect when I mention all this in case Rules is doing something squirrely; but now off to try our your new PR. |
With the new PR:
So I think we're good! |
Wow, many thanks for your digging. I wasn't aware that class RulesConfigEntity extends Entity. Great, that the PR fixes the problem. I merged it. 👍 |
Hello @bugfolder and @indigoxela. I finally have time to look into this. Thank you both for taken care of a fix... but... There is a fundamental issue with the way Ubercart handles the entity If I remember correctly (I have to check this), the So, @indigoxela was correct to suspect that there was something wrong to begin with. The fix is masking this problem, but this is likely to create issues with more contribs that act upon instances of fields for entities. @bugfolder, I'll try to dig a bit more on this in Ubercart, and will create an issue there. Additional clarification: |
To further clarify what I'm saying here: I think the fix for What I'm trying to say is that the |
Hey @argiepiano, yeah, many thanks for confirming my initial suspicion. 😉 The weird (possibly questionable) things that the Ubercart and Rules modules do, helped to clean up some undoubtedly inefficient code in filefield_paths. So this bug report provided benefit here. I'd suggest, a more in-depth discussion re entity handling should continue in the other issue queues. |
I'll watch for it (and won't distract this issue further), but will mention that in my initial investigation, I found that |
Updating filefield_paths from version 1.0.2 to version 1.0.3 crashed our Ubercart site at customer checkout. After adding a product to the cart and clicking "Checkout", the following crash ensued:
The change happened because of the change in function declaration from filefield_paths 1.0.2 to 1.0.3. In 1.0.2, it was:
But in 1.0.3, argument types are declared:
The problem is that
$instance
can be NULL, and this is what's happening in this case.That function is called from
filefield_paths_field_storage_pre_update()
, with the call happening from this loop:$instance
is set from this line near the top:In this case,
$entity_type = 'uc_order_product'
,$field['field_name'] = 'field_image_cache'
,$bundle = 'uc_order_product'
. There are no instances for this entity type, field name and bundle, sofield_info_field()
properly returns NULL (as it is documented to do).So, I believe that
filefield_paths_field_storage_pre_update()
needs to handle the case where$instance = NULL
and not try to callfilefield_paths_filefield_paths_process_file()
(or, really, any other processing inside that loop) when$instance
is NULL, now that$instance
is declared typed.Pinging @argiepiano on this, since this is Ubercart- and entity-related.
The text was updated successfully, but these errors were encountered: