Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-150

Error when fetching results from a DATETIME with value NULL

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.0.6
    • 1.0.7
    • DBAPI 2.0
    • None
    • ubuntu 20.04
      python latest
      mariadb server latest

    Description

      Hello,

      I have a quite obvious bug to report:

      I have a table row that looks like this:
      id title category date_posted date_due content file user_id
      6 test 7 10 2021-04-01 21:50:21 content 7 strawsf9cdaf.txt 16

      The problem is that i have a DATETIME field that is NULL (the date_due date is not mandatory in my app)

      It seems that after passing values to the execute() method, the fetchall() method parses returned data differently.

      First case works great Second returns the "ValueError: year 0 is out of range"

      id=("6",)
      statement1 = "select * from posts where id = 6"
      statement2 = "select * from posts where id = ?"
       
      db.cursor.execute(statement1)
      result = db.cursor.fetchall()
      for x in result:
           print(x)
       
      db.cursor.execute(statement2, id)
      result = db.cursor.fetchall()
      for x in result:
           print(x)
      

      I tried to list() the connector - same result

      I tried to change values and table column attributes - same result

      I though its a problem of versions so i updated to latest python, mariadb server and python connector (on ubuntu 20.04)- same result

      The result:

      6, 'test 7', 10, datetime.datetime(2021, 4, 1, 21, 50, 21), None, 'content 7', 'strawsf9cdaf.txt', 16)
      ValueError: year 0 is out of range

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
      File "/home/project dir/main_test3.py", line 38, in <module>
      result = db.cursor.fetchall()
      SystemError: <method 'fetchall' of 'mariadb.connection.cursor' objects> returned a result with an error set

      Process finished with exit code 1

      I posted the issue for easy reading also to stackoverflow:
      https://stackoverflow.com/questions/66963588/python-mariadb-connector-error-when-fetching-results-from-a-datetime-with-value

      Attachments

        Activity

          Tried this with the mysql connector and seems to work fine on the same database so i guess the problem is in the mariadb connector

          kiusa Kiusa Diakusen added a comment - Tried this with the mysql connector and seems to work fine on the same database so i guess the problem is in the mariadb connector
          georg Georg Richter added a comment - - edited

          Could you please also attach the sql definition of the table posts and provide the version of MariaDB server.

          Thanks!

          georg Georg Richter added a comment - - edited Could you please also attach the sql definition of the table posts and provide the version of MariaDB server. Thanks!

          Hello Georg,

          tried with null, not null and with or default value
          also tried dif charsets
          same result

          CREATE TABLE `posts` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `title` varchar(255) NOT NULL,
          `category` int(11) NOT NULL,
          `date_posted` datetime NOT NULL DEFAULT current_timestamp(),
          `date_due` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
          `content` text NOT NULL,
          `file` varchar(70) DEFAULT NULL,
          `user_id` int(11) NOT NULL,
          PRIMARY KEY (`id`),
          KEY `posts_fk_users` (`user_id`),
          KEY `posts_fk_categories` (`category`),
          CONSTRAINT `posts_fk_categories` FOREIGN KEY (`category`) REFERENCES `categories` (`id`),
          CONSTRAINT `posts_fk_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
          ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 |

          kiusa Kiusa Diakusen added a comment - Hello Georg, tried with null, not null and with or default value also tried dif charsets same result CREATE TABLE `posts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `category` int(11) NOT NULL, `date_posted` datetime NOT NULL DEFAULT current_timestamp(), `date_due` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `content` text NOT NULL, `file` varchar(70) DEFAULT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `posts_fk_users` (`user_id`), KEY `posts_fk_categories` (`category`), CONSTRAINT `posts_fk_categories` FOREIGN KEY (`category`) REFERENCES `categories` (`id`), CONSTRAINT `posts_fk_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 |

          Ooops i forgot

          mariadb --version
          mariadb Ver 15.1 Distrib 10.3.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

          kiusa Kiusa Diakusen added a comment - Ooops i forgot mariadb --version mariadb Ver 15.1 Distrib 10.3.25-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
          georg Georg Richter added a comment -

          fixed in rev. 6e50bfcbe5c485937b152c516ce94e426229ca72

          georg Georg Richter added a comment - fixed in rev. 6e50bfcbe5c485937b152c516ce94e426229ca72

          Thank you, Georg!
          Is there a way to update my current connector or i better wait for the new version?
          Thank you again

          kiusa Kiusa Diakusen added a comment - Thank you, Georg! Is there a way to update my current connector or i better wait for the new version? Thank you again
          georg Georg Richter added a comment -

          You can download the sources from Github and build the package with python setup.py build and python setup.py install.

          georg Georg Richter added a comment - You can download the sources from Github and build the package with python setup.py build and python setup.py install.

          Thank you very much!

          kiusa Kiusa Diakusen added a comment - Thank you very much!

          People

            georg Georg Richter
            kiusa Kiusa Diakusen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.