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

Error when fetching results from a DATETIME with value NULL

    XMLWordPrintable

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

          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.