def insert(self): import pymongo.errors if self.overwrite: return self.save() autoinc_key = self.run_entry.get("_id") is None while True: if autoinc_key: c = self.runs.find({}, {"_id": 1}) c = c.sort("_id", pymongo.DESCENDING).limit(1) self.run_entry["_id"] = ( c.next()["_id"] + 1 if self.runs.count_documents({}, limit=1) else 1 ) try: self.runs.insert_one(self.run_entry) return except pymongo.errors.InvalidDocument as e: raise ObserverError( "Run contained an unserializable entry." "(most likely in the info)\n{}".format(e) ) except pymongo.errors.DuplicateKeyError: if not autoinc_key: raise
def final_save(self, attempts): import pymongo try: self.runs.update_one({'_id': self.run_entry['_id']}, {'$set': self.run_entry}, upsert=True) return except pymongo.errors.InvalidDocument: self.run_entry = force_bson_encodeable(self.run_entry) print( "Warning: Some of the entries of the run were not " "BSON-serializable!\n They have been altered such that " "they can be stored, but you should fix your experiment!" "Most likely it is either the 'info' or the 'result'.", file=sys.stderr) with NamedTemporaryFile(suffix='.pickle', delete=False, prefix='sacred_mongo_fail_') as f: pickle.dump(self.run_entry, f) print("Warning: saving to MongoDB failed! " "Stored experiment entry in '{}'".format(f.name), file=sys.stderr) raise ObserverError("Warning: saving to MongoDB failed!")
def save(self): try: self.runs.update_one({'_id': self.run_entry['_id']}, {'$set': self.run_entry}) except pymongo.errors.InvalidDocument: raise ObserverError('Run contained an unserializable entry.' '(most likely in the info)')
def save(self): try: self.runs.save(self.run_entry) except AutoReconnect: pass # just wait for the next save except InvalidDocument: raise ObserverError('Run contained an unserializable entry.' '(most likely in the info)')
def save(self): import pymongo try: self.runs.update_one({"_id": self.run_entry["_id"]}, {"$set": self.run_entry}) except pymongo.errors.InvalidDocument: raise ObserverError("Run contained an unserializable entry." "(most likely in the info)")
def save(self): import pymongo.errors try: self.runs.update_one({'_id': self.run_entry['_id']}, {'$set': self.run_entry}) except pymongo.errors.AutoReconnect: pass # just wait for the next save except pymongo.errors.InvalidDocument: raise ObserverError('Run contained an unserializable entry.' '(most likely in the info)')
def insert(self): if self.overwrite: return self.save() autoinc_key = self.run_entry['_id'] is None while True: if autoinc_key: c = self.runs.find({}, {'_id': 1}) c = c.sort('_id', pymongo.DESCENDING).limit(1) self.run_entry['_id'] = c.next()['_id'] + 1 if c.count() else 1 try: self.runs.insert_one(self.run_entry) except InvalidDocument: raise ObserverError('Run contained an unserializable entry.' '(most likely in the info)') except DuplicateKeyError: if not autoinc_key: raise return