4

I'm new to Python, so maybe I'm making a newbie mistake. But this doesn't seem the kind of error I should get in this circumstance.

On a very simple SELECT statement, I'm getting a "list index out of range" error.

  sql = """
        begin tran
        -- Several update statements are in this block.

        commit tran"""
    sql = sql.format(tablename=self.tablename, **self.mappings)
    #print(sql)
    self.cursor.execute(sql, (self.catalog_id,self.catalog_id,self.catalog_id,))


    self.cursor.execute("SELECT CaptionText, DisplayOrder FROM dbo.SizeOrder where CaptionText is not NULL and len(CaptionText)>0")  #This is the line that breaks!

    size_order = {row[0].lower(): row[1] for row in self.cursor}

It's the next to last row that breaks. It's not doing any funny formatting. I don't do any of the substitutions in this problem query. When run directly against the DB, it returns over 300 records.

The trace output definitely implicates that line of code. I really suspected the next line b/c it involves indexes. But a return after the execute helped nothing.

    Traceback (most recent call last):
  File "import.py", line 782, in <module>
    main(sys.argv)
  File "import.py", line 167, in main
    db.transform_catalog((len(args)>4 and args[4] == "--skipimages") or (len(args)>5 and args[5] == "--skipimages") )
  File "import.py", line 235, in transform_catalog
    self.do_transform(skipImages)
  File "import.py", line 264, in do_transform
    self.insert_size_types()
  File "import.py", line 501, in insert_size_types
    self.cursor.execute("SELECT CaptionText, DisplayOrder FROM dbo.SizeOrder  where CaptionText is not NULL and len(Capt
ionText)>0")
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 1449, in execute
    self._free_stmt(SQL_CLOSE)
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 1971, in _free_stmt
    check_success(self, ret)
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 986, in check_success
    ctrl_err(SQL_HANDLE_STMT, ODBC_obj.stmt_h, ret, ODBC_obj.ansi)
  File "C:\Python33\lib\site-packages\pypyodbc.py", line 951, in ctrl_err
    state = err_list[0][0]
IndexError: list index out of range

What could I be doing wrong? Thanks!

2
  • 2
    This is probably a long shot but maybe it's related to a bug that is fixed in pypyodbc 1.3.3: code.google.com/p/pypyodbc/issues/detail?id=42 Commented Aug 6, 2015 at 19:45
  • it looks like you forgot to fetch the results of your query results = self.cursor.fetchall() Commented Aug 6, 2015 at 19:46

1 Answer 1

1

Definitely a bug. An unrelated error during some result processing in the library's internals, not input-related. DeepSpace's link is the likely cause.

Sign up to request clarification or add additional context in comments.

4 Comments

So ... what is the solution? Is there an upgrade or service pack or patch?
?! "...that is fixed in pyodbc 1.3.3" wasn't clear enough?
@ivan_pozdeev: it's back in 1.3.4: IndexError: list index out of range
@user443854 file another question, that is definitely something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.