Refactor sqlthread and add create test cases #1999
No reviewers
Labels
No Label
bug
build
dependencies
developers
documentation
duplicate
enhancement
formatting
invalid
legal
mobile
obsolete
packaging
performance
protocol
question
refactoring
regression
security
test
translation
usability
wontfix
No Milestone
No project
No Assignees
1 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Bitmessage/PyBitmessage-2024-12-05#1999
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "shekhar-cis/test_sqlthread_refactor"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
the PR should use consistent language dialect. In some places in this PR verbs end with
-se
(UK) and other places with-ze
(US). I don't think the project has a standard for this but I think it should be-ze
.@ -423,1 +147,4 @@
"""
Check if sqlite can store binary zeros.
"""
try:
It may be helpful to have a common error handler or at least common error messages for errors. Or, perhaps a decorator would be helpful? It would wrap the whole method in a
try
/except
, assuming we can refactor the rest of the code so that all the SQL operations can be done by dedicated methods.@ -517,3 +204,2 @@
self.conn.close()
logger.info('sqlThread exiting gracefully.')
self.initialize_sql("config_setting_ver_{}".format(settingsversion))
this should be split into multiple methods
@ -635,4 +227,4 @@
try:
self.conn.create_function("enaddr", 3, func=encodeAddress, deterministic=True)
except (TypeError, sqlite3.NotSupportedError) as err:
logger.debug(
we should have a test of what happens if there is legacy string in the database when retrieving the value
add comment
# bump sql_schema_version by one
@ -593,1 +215,3 @@
os._exit(0)
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
We should also handle
FileNotFoundError
, then log debug that the file is missing, and return.between 221 and 222 insert here a call to
sql_schema_version
@ -593,1 +215,3 @@
os._exit(0)
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
I have checked that
FileNotFoundError
is forpython3
.or we can do like
or
And
IOError
raisesIOError(2, 'No such file or directory')
@ -576,0 +210,4 @@
try:
inbox_exists = list(self.cur.execute('PRAGMA table_info(inbox)'))
if not inbox_exists:
self.initialize_sql("initialize_schema")
instead of
custom_error
maybecommand
@ -593,1 +215,3 @@
os._exit(0)
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
we seem to be missing a sqlite error handler. This should also log, but stronger severity (e.g.
error
), notdebug
only
return
should be wrapped undertry
@ -594,0 +215,4 @@
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
logger.debug('Database file already exists.')
these sections should also be in a separate function/method
I don't know if there needs to be a variable `command, why not just use the string directly?
get rid of this
return
@ -422,1 +145,4 @@
def check_columns_can_store_binary_null(self):
"""
Check if sqlite can store binary zeros.
return True
@ -593,1 +215,3 @@
os._exit(0)
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
return False
The two changes I suggested should fix the tests too.
ok I didn't explain it well:
I added an IndexError just in case.
@ -593,1 +215,3 @@
os._exit(0)
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
return False
should be after thetry/except
block so that it's consistent (returnsTrue
if no exception, otherwise returnsFalse
)@ -473,168 +191,247 @@ class sqlThread(threading.Thread):
try:
self.cur.execute(''' VACUUM ''')
except Exception as err:
replace with
error_handler
@ -473,168 +191,247 @@ class sqlThread(threading.Thread):
try:
self.cur.execute(''' VACUUM ''')
except Exception as err:
error_handler
is inelse
block.@ -473,168 +191,247 @@ class sqlThread(threading.Thread):
try:
self.cur.execute(''' VACUUM ''')
except Exception as err:
the error handling should be unified, this here isn't a special case
@ -473,168 +191,247 @@ class sqlThread(threading.Thread):
try:
self.cur.execute(''' VACUUM ''')
except Exception as err:
Added inside
error_handler
.this should also use
error_handler