[issue41638] Error message: sqlite3.ProgrammingError: You did not supply a value for binding # might be improved

Wolfgang Fahl report at bugs.python.org
Wed Aug 26 02:51:45 EDT 2020


Wolfgang Fahl <wf at bitplan.com> added the comment:

The full workaround is in https://github.com/WolfgangFahl/DgraphAndWeaviateTest/commit/f1a58d75f459bf78db327acddaf01d5cf64eb7d4

def testBindingError(self):
        '''
        test list of Records with incomplete record leading to
        "You did not supply a value for binding 2"
        see https://bugs.python.org/issue41638
        '''
        listOfRecords=[{'name':'Pikachu', 'type':'Electric'},{'name':'Raichu' }]
        for executeMany in [True,False]:
            try:
                self.checkListOfRecords(listOfRecords,'Pokemon','name',executeMany=executeMany)
                self.fail("There should be an exception")
            except Exception as ex:
                if self.debug:
                    print(str(ex))
                self.assertTrue('no value supplied for column' in str(ex))   

Giving the error messages:

INSERT INTO Pokemon (name,type) values (:name,:type)
failed: no value supplied for column 'type'

in mode "executeMany"

INSERT INTO Pokemon (name,type) values (:name,:type)
failed: no value supplied for column 'type'
record  #2={'name': 'Raichu'}

if executeMany is not used and errorDebug is on

The wrapper code is:

def store(self,listOfRecords,entityInfo,executeMany=False):
        '''
        store the given list of records based on the given entityInfo
        
        Args:
          
           listOfRecords(list): the list of Dicts to be stored
           entityInfo(EntityInfo): the meta data to be used for storing
        '''
        insertCmd=entityInfo.insertCmd
        try:
            if executeMany:
                self.c.executemany(insertCmd,listOfRecords)
            else:
                index=0
                for record in listOfRecords:
                    index+=1
                    self.c.execute(insertCmd,record)
            self.c.commit()
        except sqlite3.ProgrammingError as pe:
            msg=pe.args[0]
            if "You did not supply a value for binding" in msg:
                columnIndex=int(re.findall(r'\d+',msg)[0])
                columnName=list(entityInfo.typeMap.keys())[columnIndex-1]
                debugInfo=""
                if not executeMany:
                    if self.errorDebug:
                        debugInfo="\nrecord  #%d=%s" % (index,repr(record))
                raise Exception("%s\nfailed: no value supplied for column '%s'%s" % (insertCmd,columnName,debugInfo))
            else:
                raise pe

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41638>
_______________________________________


More information about the Python-bugs-list mailing list