Skip to content

Commit

Permalink
fixing get-or--create deprecation
Browse files Browse the repository at this point in the history
mongoengine has deprecated/removed the get_or_create function
(MongoEngine/mongoengine#300)

So this should fix it
  • Loading branch information
jtushman committed Oct 13, 2017
1 parent ed5bebe commit 6ebe589
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion monarch/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class MongoMigrationHistory(MigrationHistoryStorage, mongoengine.Document):

@classmethod
def find_or_create_by_key(cls, migration_key):
return cls.objects.get_or_create(key=migration_key)[0]
result = cls.objects(key=migration_key)
if len(result) == 1:
return result[0]
else:
return cls(key=migration_key).save()

@classmethod
def find_by_key(cls, migration_key):
Expand Down

0 comments on commit 6ebe589

Please sign in to comment.