Skip to content

Commit

Permalink
Storage: Fix handling of string facts in update_fact()
Browse files Browse the repository at this point in the history
This method was written to handle either a Fact object or a string
description of a fact. However, the string-to-Fact conversion happened
too late in the method, after `check_fact()` was called, which requires
a Fact object, leading to an error like:

    AttributeError: 'dbus.String' object has no attribute 'start_time'

This happened in particular when using the DBus UpdateFact method, which
always passes a string to `update_fact()`.

This commit ensures that the string-to-Fact conversion is done
immediately, so the rest of the method can just assume there is a Fact
method.

This fixes #671.
  • Loading branch information
ederag authored and matthijskooijman committed Mar 13, 2021
1 parent 4b51ab9 commit 864fa0f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/hamster/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ def get_fact(self, fact_id):
return self.__get_fact(fact_id)

def update_fact(self, fact_id, fact, start_time=None, end_time=None, temporary=False):
# better fail before opening the transaction
self.check_fact(fact)
self.start_transaction()
self.__remove_fact(fact_id)
# to be removed once update facts use Fact directly.
if isinstance(fact, str):
fact = Fact.parse(fact)
fact = fact.copy(start_time=start_time, end_time=end_time)
# better fail before opening the transaction
self.check_fact(fact)
self.start_transaction()
self.__remove_fact(fact_id)
result = self.__add_fact(fact, temporary)
if not result:
logger.warning("failed to update fact {} ({})".format(fact_id, fact))
Expand Down

0 comments on commit 864fa0f

Please sign in to comment.