Skip to content

Commit

Permalink
Mongo storage: If the object is new (version is 1), set the creation …
Browse files Browse the repository at this point in the history
…datetime to now
  • Loading branch information
ateska committed Jan 9, 2025
1 parent 2448800 commit ab8fb93
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion asab/storage/mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ async def execute(self, custom_data: typing.Optional[dict] = None, event_type: t
if self.Version is not None:
filtr['_v'] = int(self.Version)

# First wave (adding stuff)
if len(addobj) > 0:
coll = self.Storage.Database[self.Collection]
try:
Expand All @@ -194,6 +193,13 @@ async def execute(self, custom_data: typing.Optional[dict] = None, event_type: t
# Object might have been changed in the meantime
raise KeyError("NOT-FOUND")

if ret.get('_v') == 1 and '_c' not in ret:
# If the object is new (version is 1), set the creation datetime
await coll.update_one(
{ id_name: ret[id_name] },
{ '$set': { '_c': ret['_m'] } }
)

self.ObjId = ret[id_name]

if self.Storage.WebhookURIs is not None:
Expand Down

0 comments on commit ab8fb93

Please sign in to comment.