archivesspace-labs / ArchivesSnake

A client library for working with the ArchivesSpace API
https://archivesspace-labs.github.io/ArchivesSnake/
Other
78 stars 13 forks source link

JSONModelObject returns (rather than copies) _json, spooky action at a distance possible. #25

Closed pobocks closed 5 years ago

pobocks commented 5 years ago

So, currently, doing e.g.

resource = aspace.repositories(2).resources(2)
json = resource.json()
json['title'] = 'New Title'

Will change the result of resource._json['title'], because they're the same object.

This is... I think surprising? And potentially dangerous if we implement write functionality at the abstraction layer.

The two things I can think of to do here are:

  1. return copy(self._json) or deepcopy(self._json) instead of self._json
  2. document that the user is responsible for copying. This is basically a "we're never implementing write functionality directly in the abstraction layer, you'll need to use client or a (forthcoming) separate utility module/class/whatever.
pobocks commented 5 years ago

This has been fixed as of v0.8.1