-
Notifications
You must be signed in to change notification settings - Fork 185
Description
Describe the bug
Calling print() on a RubricAssociation object raises an AttributeError due to the str method attempting to access self.id, which does not exist on the object.
To Reproduce
- Create a rubric and associate it with an assignment using canvasapi.
- Attempt to print the returned RubricAssociation object directly using print(rubric_association).
rubric_association_info = {
"rubric_association": {
"rubric_id": rubric['rubric'].id,
"association_id": assignment.id,
"association_type": "Assignment",
"title": assignment.name,
"use_for_grading": True,
"purpose": "grading",
"bookmarked": True
}
}
rubric_association = course.create_rubric_association(**rubric_association_info)
print(rubric_association)
The following error is raised:
AttributeError: 'RubricAssociation' object has no attribute 'id'
Expected behavior
RubricAssociation.str() should not assume the object has an id attribute if it's not guaranteed to exist. It should fallback gracefully or be based on guaranteed attributes
Environment information
- Python version 3.12.8
- CanvasAPI version 3.3.0
Additional context
The Canvas API response for RubricAssociation includes an id field under the rubric_association key:
"rubric_association": {
"id": 1617,
...
}
However, the canvasapi library does not merge this data into the top-level attributes of the RubricAssociation object. As a result, attributes like self.id are not accessible, and the following str method fails:
def str(self):
return "{}, {}".format(self.id, self.association_type)
Fix suggestions:
- Flatten the rubric_association dict into the root object data before initializing the RubricAssociation object.
- Or, modify str() to use getattr(self, "id", "N/A") as a failsafe.