You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: move model attribute defaults from class level to __init__
Every model class kept its attribute defaults in the class body and relied on
them as fallbacks until __init__ (or an API resource) overwrote them. That is
what made the shared-mutable-dict bug possible in the first place: a class-level
`links = {}` / `checkSum = {...}` / `sections = {}` is one object shared by
every instance, so one object's mutation leaks into all the others.
All of them are now plain instance attributes assigned in __init__ -
HALResource (type, links, embedded), AddressableHALResource (id),
ExternalDataObject (id, display, value, externalSource, metadata), DSpaceObject
(id, uuid, name, handle, lastModified, parent, metadata, type), Item (inArchive,
discoverable, withdrawn), Community / Collection / Bundle / Bitstream / Group /
User (type and their own fields), InProgressSubmission (lastModified, step,
sections, type) and EntityType (label). No model class has a class-level
attribute left; a new test asserts that, so finding 7 cannot regress.
Verified against both repositories first: nothing reads these attributes off the
class (only `Item.from_dso`, a classmethod), nothing builds a model through
`object.__new__`, and `to_json`/`to_json_pretty` - the only readers of a model's
`__dict__` - have no callers. An exhaustive old-vs-new comparison over every
class, constructor form, `dso=` copy path and `as_dict()` reports two
differences, both deliberate: `DSpaceObject.id` and `EntityType.label` now
default to None instead of raising AttributeError when absent.
Behaviour deliberately preserved: Item still stamps `type = 'item'` only when
built from an API resource. Its class-level `type = 'item'` was dead - DSpaceObject
.__init__ always assigns self.type first, shadowing it on every instance.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
0 commit comments