Problem/Motivation

Coming from #2993663-23: Deprecate Schema::fieldSetDefault and Schema::fieldSetNoDefault, they're not used.

In case of attempted INSERT of a record with an undefined column and no default value indicated in schema, MySql returns a 1364 error code. This leads to a DatabaseExceptionWrapper being thrown instead of the more accurate IntegrityConstraintViolationException like the other drivers do.

Proposed resolution

Make so that MySql driver throws the same excpetion as the other core drivers.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new1.22 KB

Here's a test only patch that should proof the issue across different drivers.

Status: Needs review » Needs work

The last submitted patch, 2: 2999569-2-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mondrake’s picture

Title: MySql driver throws a generic DatabaseExceptionWrapper for integrity violation at insertion » MySql driver throws a generic DatabaseExceptionWrapper for integrity violation at insertion when column has no default
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new24.14 KB
new2.97 KB

So looking at how this is managed in handleQueryException, this is only applicable when an insert does not define a column and the table column has no default set.

Adjusted issue summary and title.

Let's see if this works.

Status: Needs review » Needs work

The last submitted patch, 4: 2999569-4.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new2.93 KB

Sorry wrong patch in #4, interdiff is OK.

Status: Needs review » Needs work

The last submitted patch, 6: 2999569-4.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new950 bytes
new2.97 KB

MySql error code is in errorInfo[1].

Status: Needs review » Needs work

The last submitted patch, 8: 2999569-6.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new920 bytes

In PHP 7, \RuntimeException that IntegrityConstraintViolationException extends from has a strict typehint on $code being a long. Here the PDOException would store 'HY000', which fails the signature. Converting to 0 in this case.

mondrake’s picture

StatusFileSize
new4.45 KB
new1.45 KB

Looking at the failures in #8, with this we can actually make EntityDefinitionUpdateTest::testBundleFieldCreateDeleteWithExistingEntities stronger!

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

daffie’s picture

Issue tags: +Bug Smash Initiative
daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
  1. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
    @@ -373,20 +373,18 @@ public function testBundleFieldCreateDeleteWithExistingEntities() {
         catch (\RuntimeException $e) {
    ...
    +      // Keep throwing it.
    +      throw $e;
         }
    

    These lines can be removed. They are only doing the default thing.

  2. 
    ...
    +      throw new IntegrityConstraintViolationException($message, is_int($e->getCode()) ? $e->getCode() : 0, $e);
    

    Why are we doing an is_int() test? Every where else in core we just use the $e->getCode() value.

The patch also needs a reroll.

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new4.4 KB

Rerolled patch for 9.1.x and also done changes as mentioned in #16, please review.

Status: Needs review » Needs work

The last submitted patch, 17: 2999569-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new4.4 KB
new1.46 KB

Kindly review a new patch.

daffie’s picture

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

Patch looks good. I got just one remark:

+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
@@ -482,20 +482,16 @@ public function testBundleFieldCreateDeleteWithExistingEntities() {
     catch (\RuntimeException $e) {

This line can also be removed.

Also my question from comment #16.2 is still open.

mondrake’s picture

@daffie re. #16.2 see #10.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.39 KB
new559 bytes

Here I have made changes as per comment #20.

hardik_patel_12’s picture

@daffie and @ravi.shankar , in #19 i have intentionally skipped the 16.2, as here the PDOException would store 'HY000', which fails the signature() which is mentioned mentioned by @mondrake.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All my points are addressed.
All code changes look good to me.
For me it is RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Patch looks reasonable to me, but needs a reroll.

vsujeetkumar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.59 KB

Re-roll patch created, Please review.

Status: Needs review » Needs work

The last submitted patch, 26: 2999569_26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mr.baileys’s picture

+++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
@@ -90,6 +91,24 @@ public function query($query, array $args = [], $options = []) {
+    // default value indicated in schema, MySql returns a 1364 error code.

Nitpick, and haven't looked at the patch in full, but the correct capitalization is "MySQL".

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.56 KB
new500 bytes

Fixed test, Please review.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new4.33 KB

Rerolled from #22.

EDIT - xpost with #28 and #29

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: 2999569-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

daffie’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC.

  • catch committed bacf782 on 9.1.x
    Issue #2999569 by mondrake, Hardik_Patel_12, ravi.shankar, vsujeetkumar...
catch’s picture

Status: Reviewed & tested by the community » Fixed
FILE: ...ts/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 7 | WARNING | [x] Unused use statement
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Fixed this on commit.

Committed bacf782 and pushed to 9.1.x. Thanks!

I just realised after commit, that IntegrityConstraintViolationException doesn't extend DatabaseExceptionWrapper - so if someone was catching DatabaseExceptionWrapper specifically for this case, it might fail. This seems extremely unlikely, so I don't think it even needs a change record, but noting here in case anyone wants to do one just in case. I do think it's a reason to make this issue 9.1.x only though.

mondrake’s picture

Added and published CR, https://www.drupal.org/node/3164002

Status: Fixed » Closed (fixed)

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