Problem/Motivation

For the release of Drupal 10 the minimum required version will be ??? and the json1 extension will also be required. The minimum supported version for SQLite in Drupal 10 will be determined in #3190641: [policy] Require SQLite 3.26 for Drupal 10 (same as Drupal 9) with the json1 extension required (new requirement for Drupal 10).

Proposed resolution

Update the requirements test for the SQLite database driver.

Remaining tasks

TBD

User interface changes

API changes

None

Data model changes

None

Release notes snippet

Drupal core will begin warning in the status report <a href="https://www.drupal.org/node/3259113"> if a database connection doesn't support JSON</a>, in preparation for this becoming an installation requirement in Drupal 10.

Comments

daffie created an issue. See original summary.

catch’s picture

Title: Increase minimum version requirement for SQLite to ??? and require the json1 extension » Implement json1 check for the sqlite database driver and show a warning in hook_requirements()
Version: 10.0.x-dev » 9.2.x-dev

I'm going to move this back to 9.2.x - I think we can implement the requirements test in Drupal 9, and show a warning in hook_requirements() to tell people if they don't have the extension configured and that it will be required in Drupal 10.

Then in Drupal 10 we'd just change the warning to an error and possibly update some wording.

gábor hojtsy’s picture

Title: Implement json1 check for the sqlite database driver and show a warning in hook_requirements() » Warn about upcoming JSON database support requirement in Drupal 9

Make title clearer.

gábor hojtsy’s picture

gábor hojtsy’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.08 KB
new98.19 KB

Here is a patch that works fine for me. Not sure how to do automated test for this at all.

catch’s picture

We could have a test that checks the pass case - just add it to system_requirements() testing.

No idea with the fail case, seems like it could be prohibitively complex.

gábor hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Hm, which test would that be. I could not find it. https://api.drupal.org/api/drupal/9.1.x/search/requirementstest

catch’s picture

hmm I thought we had a generic status report test, but it looks like tests/src/Functional/UpdateSystem/UpdateScriptTest.php might be the closest thing, which isn't really appropriate here.

pobster’s picture

We shouldn't have the translated string split up as it is, this won't work across all languages (for like, RTL languages but maybe others too).

There's no harm in duplicating the $requirements lines.

gábor hojtsy’s picture

@pobster: How does two individual full sentences cause that problem?

pobster’s picture

Right-to-left languages.

'value' => $json_message . ' ' . t('Currently not required, however it will be required from Drupal 10.'),

You can't guarantee the order of these sentences. Like this, they can only go in one order.

gábor hojtsy’s picture

Drupal is full of composition of larger text from full translated sentences. See system_help(). Why is this case different?

pobster’s picture

That's different as each part is separate? Nearly every line is either a dynamic list item or a heading. I mean ... it's not SO different, this is true - but using the argument "we do it badly elsewhere, so we can do it badly here" isn't the best of reasons to make translating content difficult. Someone will end up having to patch this later as part of an i18n initiative - let's just give whoever that is one less thing to do?

gábor hojtsy’s picture

StatusFileSize
new1.14 KB
new1.2 KB

I did not say we do it badly elsewhere, we did the breakup of those strings as part of an i18n initiative. Either way, I will nor be the one to decide whether this is good for commit or not, and it still requires a test to be considered for inclusion (which I don't have capacity currently to add).

andypost’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gábor hojtsy’s picture

Note that #3190641: [policy] Require SQLite 3.26 for Drupal 10 (same as Drupal 9) with the json1 extension required (new requirement for Drupal 10) does not yet specify the json1 extension as a requirement, so that would be important to document / propose there, so we don't put the cart before the horse writing code for it :D

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

StatusFileSize
new950 bytes
new1.14 KB

cleaned a bit, gonna extend \Drupal\Tests\system\Functional\System\StatusTest

avpaderno’s picture

+      Database::getConnection()->query('SELECT JSON_TYPE(\'1\')');
+      $json_message = t('Supported. Currently not required, however it will be required from Drupal 10.');
+      $json_severity = REQUIREMENT_OK;
+    }
+    catch (\Exception $e) {
+      $json_message = t('Not supported. Currently not required, however it will be required from Drupal 10.');
+      $json_severity = REQUIREMENT_WARNING;
+    }
+    $requirements['database_support_json'] = [
+      'title' => t('Database support for JSON'),
+      'severity' => $json_severity,
+      'value' => $json_message,
+    ];
+  }

Instead of using t('Not supported. Currently not required, however it will be required from Drupal 10.') and t('Supported. Currently not required, however it will be required from Drupal 10.') for the value key, it should use t('Not supported') and t('Supported') for value and t('It is currently not required, but it will be required from Drupal 10.') for description.

gábor hojtsy’s picture

Hm, good suggestion!

andypost’s picture

StatusFileSize
new1.1 KB
new1.1 KB
new90.48 KB

Addressed #20 - good idea

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.52 KB
new2.19 KB

Added basic test and refactored code a bit

catch’s picture

+++ b/core/modules/system/system.install
@@ -487,6 +487,24 @@ function system_requirements($phase) {
+      'value' => t('Supported'),
+      'description' => t('Currently not required, however it will be required from Drupal 10.'),
+    ];

I think we could shorten this to something like:

'Database JSON support will be required from Drupal 10.'

The 'not required, however it will be required' is a bit tricky to scan.

avpaderno’s picture

Just a nitpick: Currently not required, however it will be required from Drupal 10. is an example of comma-splice sentence.

It should be either It's currently not required. However, it will be required from Drupal 10. or It's currently not required, but it will be required from Drupal 10.

andypost’s picture

I find it kinda tautology - database support... supported

So description could also prevent duplicating words

Also I wonder if we should display description if supported, probably it useful only when not supported

avpaderno’s picture

Available is probably better. I suggested Supported to avoid using a phrase for which there wasn't a translation.

As for showing a description only when the support isn't available, Drupal core shows the description even when an extension is available. I would do the same here.

As for shortening the description, that could simple be It will be required from Drupal 10. The title is Database support for JSON, which means it's clear to what it will be required is referring to.

andypost’s picture

StatusFileSize
new1.93 KB
new39.41 KB
new2.11 KB

Here's updated patch - using Available and shorter description as 10.0 (like other deprecations using to, check with git grep 'is required in')

daffie’s picture

Status: Needs review » Needs work

The testbot is failing for PostgreSQL, it needs it own special version query.
My suggestion would be to create a new method, something like Drupal\Core\Database\Schema::hasJson().
The pgsql module can then override the method with its own implementation.

murilohp’s picture

StatusFileSize
new3.45 KB
new1.58 KB

I think it's a good idea @daffie, I created a new function at core/lib/Drupal/Core/Database/Connection.php::hasJson and override it at core/modules/pgsql/src/Driver/Database/pgsql/Connection.php. Let's see if the tests can pass now.

murilohp’s picture

Status: Needs work » Needs review
daffie’s picture

My guess is that it will fail for PostgreSQL. The new method needs to do something else to make it work for PostgreSQL.

murilohp’s picture

Looks like it's passing @daffie, searching at the documentation, since postgres 9.5, we have some new functions to process json values.
Do you think we should use something else to validate json datatype on postgres?

FYI: https://www.postgresql.org/docs/9.5/functions-json.html#FUNCTIONS-JSON-P...

daffie’s picture

Status: Needs review » Needs work
Issue tags: -sqlite

@murilohp: You are right. I did a quick look and missed that the method implementations are different.

  1. +++ b/core/lib/Drupal/Core/Database/Connection.php
    @@ -2185,4 +2185,18 @@ public function getPagerManager(): PagerManagerInterface {
    +  public function hasJson() {
    

    Can we add a return typehint for a boolean value.

  2. +++ b/core/lib/Drupal/Core/Database/Connection.php
    @@ -2185,4 +2185,18 @@ public function getPagerManager(): PagerManagerInterface {
    +   * @throws \Drupal\Core\Database\DatabaseExceptionWrapper
    +   * @throws \Drupal\Core\Database\IntegrityConstraintViolationException
    +   * @throws \InvalidArgumentException
    

    Can we remove these exceptions and add a try and catch statement.

  3. The try and catch statement can be removed from the file "system.install".
murilohp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.35 KB
new2.08 KB

Thanks for the review @daffie! Here's a patch addressing #34.

murilohp’s picture

Do you guys have any idea of what happened with the tests from #35? At the first moment I thought it could be an infrastructure error, but I think that's not the case.

cilefen’s picture

PHP Parse error: syntax error, unexpected ')', expecting '|' or variable (T_VARIABLE) in /var/www/html/core/modules/pgsql/src/Driver/Database/pgsql/Connection.php on line 378

murilohp’s picture

StatusFileSize
new3.36 KB
new848 bytes

Thanks @cilefen! Let's see the tests now.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes look good to me.
The testbot is happy for all 3 supported databases.
There is a test added.
For me it is RTBC.

  • catch committed 206d6ee on 10.0.x
    Issue #3192487 by andypost, murilohp, Gábor Hojtsy, daffie, pobster,...
catch’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed
Issue tags: +9.4.0 release notes

Committed 206d6ee and pushed to 10.0.x. Thanks!

Realised there wasn't a change record for this while committing it, so added one.

niklan’s picture

Is that correct that this change is states for Drupal 9.4.0 here and in change records, but only pushed in 10.0.x branch.

It will be cherry-picked to 9.4.x, or it's Drupal 10 feature?

catch’s picture

Status: Fixed » Reviewed & tested by the community

@Niklan - not correct, I failed to push the cherry-pick successfully. Back to RTBC until that happens.

daffie’s picture

The patch has been committed to the D10.0 branch. Now we need one for the D9.4 branch.

  • catch committed 2a40c8f on 9.4.x
    Issue #3192487 by andypost, murilohp, Gábor Hojtsy, daffie, pobster,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

It's a clean cherry-pick to 10.x, I just didn't do it properly (but have now).

We'll need a follow-up to make this a requirement error in 10.x though.

daffie’s picture

We'll need a follow-up to make this a requirement error in 10.x though.

@catch: We have #3203193: Fail install if JSON is not supported by the database in Drupal 10 for that.

gábor hojtsy’s picture

Opened #3259311: Fix database JSON detection for PostgreSQL to fix this in Upgrade Status, it would break the same way for PostgreSQL.

mondrake’s picture

Status: Fixed » Needs work

If a contrib driver has not implemented the ::hasJson() method, the status report will be WSOD. I think we should also check that the method exists before calling it, at least in D9.4.

mondrake’s picture

Also, we are missing a test here, maybe in ConnectionTest.

daffie’s picture

I think we should also check that the method exists before calling it, at least in D9.4.

We have added the method to the class Drupal\Core\Database\Connection. Every database driver extends that class, therefor the new method should exists.

@mondrake: If you have an example of a contrib database driver that already has the method hasJson() then please show us.

mondrake’s picture

Status: Needs work » Fixed

@daffie you're right, the method will be there but failing if the syntax is not appropriate. Sorry for the noise, thanks. (A KernelTest would still be helpful, but can be followup).

daffie’s picture

@mondrake: If you create the issue and the patch, then I will review it. :)

mondrake’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.