Skip to content

Commit

Permalink
db: prevent dbulog writing to file if lazy loaded
Browse files Browse the repository at this point in the history
If DatabaseULog is lazy loaded it doesn't have data, so it will fail if
trying to write to file.
  • Loading branch information
hermankolden committed Jun 29, 2024
1 parent 71f57a6 commit b2a398b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pyulog/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(self, db_handle, primary_key=None, log_file=None, lazy=True, **kwar

self._pk = primary_key
self._db = db_handle
self._lazy_loaded = lazy
if log_file is not None:
self._sha256sum = DatabaseULog.calc_sha256sum(log_file)

Expand All @@ -187,6 +188,11 @@ def __eq__(self, other):
return other.__eq__(self)
return super().__eq__(other)

def write_ulog(self, path):
if self._lazy_loaded:
raise ValueError('Cannot write after lazy load because it has no datasets.')
super().write_ulog(path)

@property
def primary_key(self):
'''The primary key of the ulog, pointing to the correct "ULog" row in the database.'''
Expand Down Expand Up @@ -400,6 +406,7 @@ def load(self, lazy=True):
self._changed_parameters.append((timestamp, key, value))

cur.close()
self._lazy_loaded = lazy

def get_dataset(self, name, multi_instance=0, lazy=False, db_cursor=None, caching=True):
'''
Expand Down

0 comments on commit b2a398b

Please sign in to comment.