Skip to content

Commit

Permalink
Fixed Nul Error on prepare psycopg2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieboldianus committed Jun 19, 2018
1 parent 2d686a9 commit e319d58
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion classes/fieldMapping.py
Expand Up @@ -164,7 +164,8 @@ def extractPost(self,jsonStringDict, userPkey = None):
if userRecord:
self.lbsnRecords.AddRecordsToDict(userRecord)
else:
self.log.warning(f'Record {self.lbsnRecords.CountGlob}: No User record found for post: {post_guid} (post saved without userid)..')
self.log.warning(f'Record {self.lbsnRecords.CountGlob}: No User record found for post: {post_guid} (post saved without userid)..')
print(f'Record {self.lbsnRecords.CountGlob}', end='\r')
#self.log.warning(f'{originalString}')
#input("Press Enter to continue... (post will be saved without userid)")

Expand Down
8 changes: 6 additions & 2 deletions classes/helperFunctions.py
Expand Up @@ -106,7 +106,7 @@ def null_check(recordAttr):
return None
else:
# This function will also remove Null bytes from string, which aren't supported by Postgres
if isinstance(recordAttr, basestring):
if isinstance(recordAttr, str):
recordAttr = helperFunctions.clean_null_bytes_from_str(recordAttr)
return recordAttr

Expand Down Expand Up @@ -140,7 +140,7 @@ def decode_stacked(document, pos=0, decoder=JSONDecoder()):
raise
yield obj

def clean_null_bytes_from_str(self,str):
def clean_null_bytes_from_str(str):
str_without_null_byte = str.replace('\x00','')
return str_without_null_byte

Expand Down Expand Up @@ -207,7 +207,11 @@ def MergeExistingRecords(self, newrecord, dict):
dict[pkeyID] = self.deepCompareMergeMessages(dict[pkeyID],newrecord)
return
else:
# just count new entries
self.CountGlob += 1
if self.CountGlob % 1000 == 0: #modulo
print(f'Record {self.CountGlob}', end='\r')
sys.stdout.flush()
self.update_keyHash(newrecord) # update keyHash only necessary for new record
dict[pkeyID] = newrecord

Expand Down
4 changes: 2 additions & 2 deletions classes/submitData.py
Expand Up @@ -335,11 +335,11 @@ def submitBatch(self,insert_sql):
print(f'TransactionIntegrityError, inserting language "{missingLanguage}" first..')
#self.dbConnection.rollback()
self.dbCursor.execute("ROLLBACK TO SAVEPOINT submit_recordBatch")
insert_sql = '''
insert_language_sql = '''
INSERT INTO "language" (language_short,language_name,language_name_de)
VALUES (%s,NULL,NULL);
'''
self.dbCursor.execute(insert_sql,(missingLanguage,))
self.dbCursor.execute(insert_language_sql,(missingLanguage,))
#self.prepareLbsnRecord(record,type_name)
except ValueError as e:
self.log.warning(f'{e}')
Expand Down

0 comments on commit e319d58

Please sign in to comment.