Changes between Version 1 and Version 2 of Ticket #35658


Ignore:
Timestamp:
Aug 6, 2024, 3:27:06 AM (4 months ago)
Author:
David
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #35658 – Description

    v1 v2  
    1 With [https://github.com/un1t/django-cleanup django-cleanup] installed, when copying a file using the `InMemoryStorage` into an other model by using:
     1Using the `InMemoryStorage` into an other model by using:
    22
    33{{{#!python
     
    99# script.py
    1010
    11 first_obj = MyModel.objects.create(attachment=ContentFile(b'content', 'myfile.txt')
    12 second_obj = MyModel.objects.create(attachment=first_obj.attachment.file)
     11obj = MyModel.objects.create(attachment=ContentFile(b'content', 'myfile.txt')
     12repr(obj.attachment)
    1313}}}
    1414
    15 An excetption is raised:
    16 
    17 {{{
    18 
    19 instance = <[AttributeError("'InMemoryFileNode' object has no attribute 'name'") raised in repr()] Attachment object at 0x70e62f1a0ee0>
    20 using = <[AttributeError("'InMemoryFileNode' object has no attribute 'name'") raised in repr()] Attachment object at 0x70e62f1a0ee0>
    21     def fields_for_model_instance(instance, using=None):
    22         '''
    23             Yields (name, descriptor) for each file field given an instance
    24             Can use the `using` kwarg to change the instance that the `FieldFile`
    25             will receive.
    26         '''
    27         if using is None:
    28             using = instance
    29         model_name = get_model_name(instance)
    30         deferred_fields = instance.get_deferred_fields()
    31         for field_name in get_fields_for_model(model_name, exclude=deferred_fields):
    32             fieldfile = getattr(instance, field_name, None)
    33 >           yield field_name, fieldfile.__class__(using, fieldfile.field, fieldfile.name)
    34 E           AttributeError: 'NoneType' object has no attribute 'field'
    35 deferred_fields = set()
    36 field_name = 'attachment'
    37 fieldfile  = None
    38 instance   = <[AttributeError("'InMemoryFileNode' object has no attribute 'name'") raised in repr()] Attachment object at 0x70e62f1a0ee0>
    39 model_name = 'tickets.attachment'
    40 using      = <[AttributeError("'InMemoryFileNode' object has no attribute 'name'") raised in repr()] Attachment object at 0x70e62f1a0ee0>
    41 ../.venv/lib/python3.10/site-packages/django_cleanup/cache.py:86: AttributeError
    42 }}}
     15An excetption is raised: `AttributeError("'InMemoryFileNode' object has no attribute 'name'") raised in repr()`
    4316
    4417
Back to Top