Opened 6 weeks ago

Last modified 5 weeks ago

#35658 closed Bug

[Bug] InMemoryFileNode has no attribute "name" — at Version 2

Reported by: David Owned by:
Component: File uploads/storage Version: 4.2
Severity: Normal Keywords: storage
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by David)

Using the InMemoryStorage into an other model by using:

# models.py

class MyModel(models.Model):
    attachment = models.FileField(...)

# script.py

obj = MyModel.objects.create(attachment=ContentFile(b'content', 'myfile.txt') 
repr(obj.attachment)

An excetption is raised: AttributeError("'InMemoryFileNode' object has no attribute 'name'") raised in repr()

This may be caused by the fact that InMemoryFileNode inheriths from ContentFile but does not use the name attribute nor uses the base class __init__ method:

https://github.com/django/django/blob/509763c79952cde02d9f5b584af4278bdbed77b2/django/core/files/storage/memory.py#L48-L52

This resulting in a partially initialized object without an important property.

Change History (2)

comment:1 by David, 6 weeks ago

Description: modified (diff)

comment:2 by David, 6 weeks ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top