dml_write_exception inside a delegated transaction with DB logging enabled

Re: dml_write_exception inside a delegated transaction with DB logging enabled

ved David Mudrák -
Antal besvarelser: 0
Billede af Core developers Billede af Documentation writers Billede af Moodle HQ Billede af Particularly helpful Moodlers Billede af Peer reviewers Billede af Plugin developers Billede af Plugins guardians Billede af Testers Billede af Translators

This is the patch I have applied to get more debugging info:

diff --git a/lib/dml/pgsql_native_moodle_database.php b/lib/dml/pgsql_native_moodle_database.php
index 97d94905ff..aca91ea529 100644
--- a/lib/dml/pgsql_native_moodle_database.php
+++ b/lib/dml/pgsql_native_moodle_database.php
@@ -966,6 +966,9 @@ class pgsql_native_moodle_database extends moodle_database {
         $sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($values) $returning";
         $this->query_start($sql, $params, SQL_QUERY_INSERT);
         $result = pg_query_params($this->pgsql, $sql, $params);
+        if (!$result) {
+            debugging($this->get_last_error(), DEBUG_DEVELOPER);
+        }
         $this->query_end($result);

         if ($returning !== "") {

With it, my upserting code throws an error (which is expected) followed by another error by the query_log() call:

++ ERROR:  duplicate key value violates unique constraint "mdl_amossnap_comlanbrastr2_uix"
DETAIL:  Key (component, lang, branch, stringid)=(tool_wp, en, 3700, loading) already exists. ++
* line 970 of /lib/dml/pgsql_native_moodle_database.php: call to debugging()
* line 1020 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
* line 1014 of /local/amos/mlanglib.php: call to pgsql_native_moodle_database->insert_record()
* line 126 of /local/amos/cli/import-strings.php: call to mlang_stage->commit()
++ ERROR:  current transaction is aborted, commands ignored until end of transaction block ++
* line 970 of /lib/dml/pgsql_native_moodle_database.php: call to debugging()
* line 1020 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
* line 538 of /lib/dml/moodle_database.php: call to pgsql_native_moodle_database->insert_record()
* line 481 of /lib/dml/moodle_database.php: call to moodle_database->query_log()
* line 248 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
* line 972 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
* line 1020 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
* line 1014 of /local/amos/mlanglib.php: call to pgsql_native_moodle_database->insert_record()
* line 126 of /local/amos/cli/import-strings.php: call to mlang_stage->commit()
PHP Warning:  pg_fetch_assoc() expects parameter 1 to be resource, boolean given in /opt/app/lib/dml/pgsql_native_moodle_database.php on line 975