MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / __setattr__

Method __setattr__

gridfs/synchronous/grid_file.py:1226–1242  ·  view source on GitHub ↗
(self, name: str, value: Any)

Source from the content-addressed store, hash-verified

1224 raise AttributeError("GridIn object has no attribute '%s'" % name)
1225
1226 def __setattr__(self, name: str, value: Any) -> None:
1227 # For properties of this instance like _buffer, or descriptors set on
1228 # the class like filename, use regular __setattr__
1229 if name in self.__dict__ or name in self.__class__.__dict__:
1230 object.__setattr__(self, name, value)
1231 else:
1232 # All other attributes are part of the document in db.fs.files.
1233 # Store them to be sent to server on close() or if closed, send
1234 # them now.
1235 self._file[name] = value
1236 if self._closed:
1237 if _IS_SYNC:
1238 self._coll.files.update_one({"_id": self._file["_id"]}, {"$set": {name: value}})
1239 else:
1240 raise AttributeError(
1241 "GridIn does not support __setattr__ after being closed(). Set the attribute before closing the file or use GridIn.set() instead"
1242 )
1243
1244 def set(self, name: str, value: Any) -> None:
1245 self._file[name] = value

Callers 5

__init__Method · 0.45
_ensure_indexesMethod · 0.45
abortMethod · 0.45
closeMethod · 0.45
__exit__Method · 0.45

Calls 1

update_oneMethod · 0.45

Tested by

no test coverage detected