Hello,
I have recently updated to 8.x-1.0-beta3 on my site (Drupal 8.6.9).
Prior to this update, I have been using the module without problem to grant write permissions to more than one user on specific nodes.
However, the first time I tried to use it after updating to beta3, whenever I type the user's name and click 'search' in order to find them and then grant the necessary permissions, site crashes with the following error:
(I am trying to grant access to nodes of a specific content type to users of specific role, both of which used to function without problems before).
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)) WHERE na.nid = '259' AND na.realm = 'nod' at line 1: SELECT count(*) FROM {node_access} na LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as int)) WHERE na.nid = :nid AND na.realm = :realm AND r.entity_id = :uid AND :grant_type = :one LIMIT 0, 1; Array ( [:nid] => 259 [:realm] => nodeaccess_rid [:uid] => 370 [:grant_type] => grant_view [:one] => 1 ) στην Drupal\nodeaccess\Form\GrantsForm->buildForm() (line 127 from /var/www/www-dev/modules/nodeaccess/src/Form/GrantsForm.php).
I read in the release notes that SQL queries were refactored in this beta3 release - could this be the problem?
PS - This is the first issue I post for a drupal module, I am still a newbie - please let me know if I can provide more help and data. I hope this can be resolved, it is an extremely useful module.
.........................
(error details from original issue summary)
.........................
</br></br><em class="placeholder">Drupal\Core\Database\DatabaseExceptionWrapper</em>: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int))
WHERE na.nid = '359'
AND na.realm = 'nod' at line 1:
SELECT count(*) FROM {node_access} na
LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as int))
WHERE na.nid = :nid
AND na.realm = :realm
AND r.entity_id = :uid
AND :grant_type = :one LIMIT 0, 1; Array
(
[:nid] => 359
[:realm] => nodeaccess_rid
[:uid] => 370
[:grant_type] => grant_view
[:one] => 1
)
in <em class="placeholder">Drupal\nodeaccess\Form\GrantsForm->buildForm()</em> (line <em class="placeholder">127</em> of <em class="placeholder">modules/nodeaccess/src/Form/GrantsForm.php</em>). <pre class="backtrace">Drupal\Core\Database\Statement->execute(Array, Array) (Line: 625)
Drupal\Core\Database\Connection->query('
SELECT count(*) FROM {node_access} na
LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as int))
WHERE na.nid = :nid
AND na.realm = :realm
AND r.entity_id = :uid
AND :grant_type = :one LIMIT 0, 1', Array, Array) (Line: 358)
Drupal\Core\Database\Driver\mysql\Connection->query('
SELECT count(*) FROM {node_access} na
LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as int))
WHERE na.nid = :nid
AND na.realm = :realm
AND r.entity_id = :uid
AND :grant_type = :one LIMIT 0, 1', Array, Array) (Line: 540)
Drupal\Core\Database\Driver\mysql\Connection->queryRange('
SELECT count(*) FROM {node_access} na
LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as int))
WHERE na.nid = :nid
AND na.realm = :realm
AND r.entity_id = :uid
AND :grant_type = :one', 0, 1, Array) (Line: 127)
Drupal\nodeaccess\Form\GrantsForm->buildForm(Array, Object, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder->retrieveForm('nodeaccess_grants_form', Object) (Line: 368)
Drupal\Core\Form\FormBuilder->rebuildForm('nodeaccess_grants_form', Object, Array) (Line: 625)
Drupal\Core\Form\FormBuilder->processForm('nodeaccess_grants_form', Array, Object) (Line: 318)
Drupal\Core\Form\FormBuilder->buildForm('nodeaccess_grants_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)| Comment | File | Size | Author |
|---|---|---|---|
| #27 | 3033703-cast-type-check-3.patch | 493 bytes | ollie222 |
| #19 | 3033703-cast-type-check-2.patch | 1.42 KB | ollie222 |
| #17 | 3033703-cast-type-check.patch | 1.19 KB | ollie222 |
| #5 | Grants Drupal partners CMS.png | 54.82 KB | pvsureshmca |
| #3 | 3033703-cast-from-varchar-to-unsigned.patch | 944 bytes | rpataca |
Comments
Comment #2
tkogias commentedthis is the error from the logs, it's the same error but I copy it here because it's probably more readable (?)..
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'int)) WHERE na.nid = '259' AND na.realm = 'nod' at line 1: SELECT count(*) FROM {node_access} na LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as int)) WHERE na.nid = :nid AND na.realm = :realm AND r.entity_id = :uid AND :grant_type = :one LIMIT 0, 1; Array ( [:nid] => 259 [:realm] => nodeaccess_rid [:uid] => 370 [:grant_type] => grant_view [:one] => 1 ) στην Drupal\nodeaccess\Form\GrantsForm->buildForm() (line 127 from /var/www/www-dev/modules/nodeaccess/src/Form/GrantsForm.php).
Comment #3
rpataca commentedHaving the same issue - thought it was the beta3 version but looks like the dev version is throwing the same error.
I debugged the issue and found that it was casting a VARCHAR to INT which doesn't look like its supported anymore(?!?!) Not a SQL guru but found reference to it here.
https://stackoverflow.com/questions/12126991/cast-from-varchar-to-int-mysql
I created a patch to CAST to UNSIGNED instead and it appears to be working.
Comment #4
tkogias commentedThanks rpataca,
I will try your patch at the end of next week and will give some feedback here (by editing this message).
Comment #5
pvsureshmca commentedHi
I am also facing the same problem in Drupal 8.7.3 and PHP 7.2.19
Please refer the attached image for your more reference
Comment #6
pvsureshmca commentedComment #7
pvsureshmca commentedThis patch is not working for me in Drupal 8.7.3
I am getting the mismatch error with version 8.x-1.0-beta3
Comment #8
pvsureshmca commentedThe only problem is the mismatching of the line number. I am getting this line in 115 instead of 112.
It is working perfectly once I change UNSIGNED.
LEFT JOIN {user__roles} r ON (na.gid = CAST(r.roles_target_id as UNSIGNED))Comment #9
alisonFYI I'm reviewing this issue and #3059918: I have an SQL syntax error in Drupal\nodeaccess\Form\GrantsForm->buildForm() -- they seem to be the same problem, just gonna compare patches/etc. to make sure they're truly the same, and pick one to keep.
.........................
Thank you for the report, @tkogias! In case it helps for next time, here's an issue summary template you can work from (you'll also see a link to it on the "Create new issue" page):
https://www.drupal.org/node/1155816
Comment #10
alison"Update" sort of...
I can reproduce the issue on simplytest.me, but for some reason, it isn't happening on a "real site" where I'm running the module. Anyway, just trying to reproduce it / figure out what's different btwn these two environments.
Comment #11
falco010Hi,
Had similar error on our live sites, however I could not reproduce it locally.
The difference between SQL version was this:
Server database version
5.7.27
Local machine SQL version
5.5.5
So it seems that somewhere after SQL version 5.5+ there was a change in this.
However the provided patch #3 solved the error for us.
Comment #12
alisonThanks for the info and review, sorry for the delayed response! I'll circle back to this issue by the end of the week.
Comment #13
alisonThanks for the info, @Falco010 -- unfortunately, I do actually have mostly the same specs locally + on simplytest.me (5.7.27).
(my live site is on Pantheon, and the DB server version says "5.5.5-10.0.23-MariaDB-log" and like, I really don't know what that means... I've searched and poked around, my best guess, when I connect to the DB and look at the version info in variables, I think it's actually equivalent to mysql 5.6.26... but i'm really not sure...)
Anyway, I'll the patch in simplytest.me tomorrow. I don't love not knowing why the problem isn't happening "here and there" -- especially with the mysql version being the same between simplytest.me and my local (I really liked that theory!!) -- but, I'll try it on simplytest.me and see what I think.
Thanks for the review and info!
Comment #14
alisonSorry for the delay, folks. I'll try to circle back to this issue by the end of the week -- no promises, but I will try!
(Meanwhile, if anyone has insights re: why the errors happen "here and there," I would *LOVE* to hear them.)
Comment #15
alisonI sincerely believe that this is a real issue, but I can't seem to reliably reproduce it. I need more info before before I can proceed. Very sorry for the situation, maybe we can move it forward during extended quarantine 🤞 Here's hoping.
Comment #16
ollie222 commentedI've just come across this issue and it appeared when trying to search for a user on the node grants tab.
The issue is caused by Mysql's CAST function and the types that it supports. For some reason the list of types it supports is not the same as the list of data types that it supports.
The list of types can be found at https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast
MariaDB is similar and is billed as a drop in replacement however they are not identical and there are small differences and I think this s one of them.
MariaDB's CAST function does support the INT type but doesn't support the SIGNED type that mysql needs.
Information on the MariaDB CAST function is at https://mariadb.com/kb/en/cast/ and the data types it supports are at https://mariadb.com/kb/en/data-types/ .
I don't see any obvious way using the database API to let PDO sort out the cast so that means you'll need to handle it. The database API can return the server version number which will be something like "5.7.25" for Mysql.
I think MariaDB always includes the word MariaDB in the version number like in your example "5.5.5-10.0.23-MariaDB-log" so we could check for that.
The attached patch does a basic check and uses the correct type syntax.
I also seem to remember that PostgreSQL using the type 'integer' so that may need a case too if you want to account for that.
Comment #17
ollie222 commentedSorry I forgot to attach the patch in #16.
Comment #18
chrisfromredfinOllie's patch in #17 is working for me; MySql 5.7.29.
I've reviewed the code, which looks fine. If someone can test this on Postgres it could move to RTBC.
Comment #19
ollie222 commented@cwells,
The original patch will fail for PostgreSQL as it's not the same as MySQL.
I've attached a new patch with a check for PostgreSQL which sets the cast type to 'integer' which I think is what PostgreSQL needs however as I don't use PostgreSQL someone else will need to confirm as Google seems to mention 'integer' and 'int', maybe it depends on version.
For MariaDB and Mysql which are the more common options it should still work.
Comment #20
dianacastillo commentedpatch 17 worked for me . i hope they add it to the next update.
Comment #22
elusivemind commentedIn dev branch
Comment #23
elusivemind commentedComment #24
ollie222 commented@ElusiveMind
Great to see patch #17 fixed in dev and it'll suit most people as MySQL and MariaDB are the common databases but the patch in #19 should fix PostgreSQL too (although I've not tested it and for some reason I added it to be tested against Drupal 7 not 8.
Comment #26
elusivemind commentedGood catch. This is in the dev branch. I will add it for the next release but I'd like to work through a few more tickets before I do so and also begin compatibility testing with Drupal 9. In the meanwhile, dev can be used. Thanks for your assist!
Comment #27
ollie222 commentedAs MySQL and MariaDB are the most popular then the patch you've added will make it work for most people.
If it helps and you want to revisit it then I've attached a patch for PostgreSQL against the latest dev version.
I don't use PostgreSQL so can't check it myself but maybe others can but this patch shouldn't break MySQL and MariaDB.