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/Motivation
Receiving error: Notice: Trying to get property of non-object in optimizedb_admin( ) (line 217 of sites/all/modules/contrib/optimizedb/optimizeddb.module). How to fix this?
Comment | File | Size | Author |
---|---|---|---|
#3 | 3186413-3.patch | 758 bytes | mcdruid |
|
Comments
Comment #2
mcdruidThis is a little tricky.
The MySQL query in question is:
Because quoting of table names was introduced in 7.76 to support MySQL 8, this will be replaced with something like:
That means the table name won't match and db_query returns FALSE.
Doing quoting of table names via the replacement of curly braces for table prefixing is a bit of a hack, but was the least bad solution to retrofit MySQL 8 support into D7.
We had to remove the quoting of table names in at least one place for schema queries, which is quite a similar situation to this:
https://git.drupalcode.org/project/drupal/-/blob/7.77/includes/database/...
It may be possible to rewrite this query such that it doesn't use the curly braces and therefore isn't affected by the table name quoting.
One simple solution might be to remove the curly braces and take advantage of the fact that it's a LIKE pattern e.g.:
That'd probably work in many cases including where there's a prefix on the table name. However, it might cause problems if there are a multiple sites using prefixes to share the same database.
You might be able to do something pragmatic like use the database API to prefix the table name, but then remove any quotes before passing the pattern to this query. I've not looked at how that would work in any depth though.
I wouldn't be surprised if there are other queries in this module that might be affected in a similar way.
A workaround for any affected sites that don't need the table name quoting (e.g. they're on earlier versions of MySQL) is to set this variable to an empty string which disables identifier quoting and should thus avoid this issue:
Comment #3
mcdruidThis is quite ugly, but it works AFAICS.
There may be a more elegant way to do this via the existing db api, or perhaps we need to add a way of accessing prefixed but unquoted table names.
Comment #4
rczurek CreditAttribution: rczurek commentedMcdruid: This is way too complex for me. I will wait for the Database Optimization module update. I have disabled and removed the module for now and the errors disappeared as I expected. Should we notify the maintainer?
Comment #5
sergeypavlenko CreditAttribution: sergeypavlenko commentedHi, all
I’m watching on this issue. Soon I will check patch.
Comment #6
rczurek CreditAttribution: rczurek commentedThank you sergeypavlenko!
Comment #7
rayjames CreditAttribution: rayjames commentedHi, I too have this same issue after updating to Drupal 7.77. Waiting for official update to module as well. Thanks for your time and help on this. Much appreciated.
Comment #9
sergeypavlenko CreditAttribution: sergeypavlenko commentedHi
@mcdruid, thanks for the patch! I not found other fast way for fix this problem. Now you patch is best way. Thanks! Pushed to dev version.
For me strange, in drupal 7.77 formed problem with prefixes, and not proposed simple variants for working modules.
Created new release 7.x-1.7.
Comment #10
sergeypavlenko CreditAttribution: sergeypavlenko commentedComment #11
rczurek CreditAttribution: rczurek commentedThank you to all involved!
Comment #12
rayjames CreditAttribution: rayjames commentedThanks everyone. Fast response, good fix. You rock! Much appreciated!