Skip to content

Keep nested objects when edit refreshes attributes - #722

Open
dbosk wants to merge 1 commit into
ucfopen:developfrom
dbosk:issue/721-submission-edit-attachments
Open

dbosk wants to merge 1 commit into
ucfopen:developfrom
dbosk:issue/721-submission-edit-attachments

Conversation

@dbosk

@dbosk dbosk commented Oct 15, 2026

Copy link
Copy Markdown

Proposed Changes

  • Submission and Assignment convert their nested objects (attachments → File, overrides → AssignmentOverride) in a set_attributes override instead of in __init__.
  • Submission.edit and Assignment.edit refresh the object with self.set_attributes(...) instead of super(...).set_attributes(...), so the refresh goes through the same conversion.
  • Tests: an edit whose response carries attachments/overrides leaves File/AssignmentOverride objects (both fail on develop); an edit whose response omits attachments keeps the existing File objects.
  • CHANGELOG entry under Unreleased.

Fixes #721.

Design

CanvasObject.__init__ sets _requester and then calls self.set_attributes(attributes), so a subclass override of set_attributes already runs when the object is created. Putting the conversion there means creation and every refresh share one code path, rather than duplicating the conversion in each method that refreshes. The refresh call sites had to change from super(X, self).set_attributes to self.set_attributes, since the explicit super call is what bypassed the conversion.

Behaviour is otherwise unchanged:

  • Submission.attachments is still [] when the payload has no attachments.
  • Assignment.overrides is still only set when the payload has overrides.
  • A refresh whose response omits the key leaves the existing objects alone.

I surveyed the other classes that wrap nested objects in __init__. GroupedSubmission and SearchResult have no method that refreshes self, so they are not affected and are left as they are.

An alternative would be a declarative mapping on CanvasObject (e.g. _nested = {"attachments": File}) handled in the base set_attributes. It is more general but touches every class. I kept to the per-class override, which is the smaller change, and am happy to do the general version if you prefer it.

🤖 Generated with Claude Code

https://claude.ai/code/session_014EWzn81BUhtfWseuDtUBjx

Submission.__init__ wraps attachments as File objects and
Assignment.__init__ wraps overrides as AssignmentOverride objects, but
their edit methods refresh the object through
super().set_attributes(...), which bypasses that conversion and leaves
plain dicts behind.

Move the conversion into a set_attributes override in each class.
CanvasObject.__init__ already calls self.set_attributes, so the same
code now runs on creation and on refresh, and edit calls
self.set_attributes instead of the base class method.

Fixes ucfopen#721.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014EWzn81BUhtfWseuDtUBjx

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Submission.edit leaves attachments as dicts instead of File objects

1 participant