canvasapi icon indicating copy to clipboard operation
canvasapi copied to clipboard

File objects get attribute `content-type` which must be accessed through `getattr`

Open dbosk opened this issue 6 months ago • 2 comments

Describe the bug

File objects get attribute content-type which must be accessed through getattr. All other attributes can be accessed by some_file.attribute, but due to the - that doesn't work for the content-type attribute.

To Reproduce

Steps to reproduce the behavior:

Get an attachment from a submission (submission.attachments). Then one must use getattr(attachment, "content-type") to get the content type. But one can access attachment.filename by dot notation.

Expected behavior

I would expect the content-type attribute to be translated to content_type.

Environment information

  • Python version (python --version): Python 3.10.12
  • CanvasAPI version (pip show canvasapi):
Name: canvasapi
Version: 3.2.0
Summary: API wrapper for the Canvas LMS
Home-page: https://github.com/ucfopen/canvasapi
Author: University of Central Florida - Center for Distributed Learning
Author-email: [email protected]
License: MIT License
Location: /home/dbosk/.cache/pypoetry/virtualenvs/canvaslms-WPDgHmeP-py3.10/lib/python3.10/site-packages
Requires: arrow, pytz, requests
Required-by: canvaslms

Additional context

Probably adding a translation of - to _ in CanvasObject.set_attributes should suffice. Not sure if this would break anything.

dbosk avatar Feb 19 '24 20:02 dbosk

Can I look into this?

OscarSong2003 avatar Apr 01 '24 18:04 OscarSong2003

#650 I attempted to solve this issue by editing CanvasObject.set_attributes and adding some test cases. Please let me know if there is anything I need to change.

nayanpaa avatar Apr 23 '24 02:04 nayanpaa