# Setting FileField/ImageField where file has no name

**URL:** <https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192>\
**Category:** Django Internals\
**Created:** [April 15, 2024, 3:00pm UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192 "2024-04-15T15:00:10Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 17, 2024, 3:04pm UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/21 "2024-04-17T15:04:55Z")

</div>

> [@Lily-Foote](#):
>
> An exception from `instance.save()` if the `name` is not set to a valid value (or at all) makes sense to me.

Would the exception need to come from lower down in the stack? (Perhaps from the storages class?) It seems to me that you could have a storage class that creates an arbitrary name if one isn’t provided. (At least it looks to me like the Storage class API makes that a feasible option.) Should the default file system storage do this?

> [@Lily-Foote](#):
>
> The amount of back and forth between you both about this is a sign to me that Django is confusing here.

Nope, this is on me. I waded into an area where I thought my knowledge was greater than what turns out to be the case.  
This was my first time really diving into this topic, and it has taken me some time to wrap my head around what is going on, along with trying to really understand the issue being presented. (I also hold the general opinion that everything within the ORM internally should be labeled “There be dragons here!”, but that’s a different issue.)

---

<div class="post-metadata">

**Author:** ![Lily-Foote](https://avatars.discourse-cdn.com/v4/letter/l/c37758/32.png) [@Lily-Foote](https://forum.djangoproject.com/u/Lily-Foote)\
**Post date:** [April 17, 2024, 3:10pm UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/22 "2024-04-17T15:10:54Z")

</div>

> [@KenWhitesell](#):
>
> Should the default file system storage do this?

Sounds sensible to me.

---

<div class="post-metadata">

**Author:** ![john-parton](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/john-parton/32/20634_2.png) [@john-parton](https://forum.djangoproject.com/u/john-parton)\
**Post date:** [April 17, 2024, 3:11pm UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/23 "2024-04-17T15:11:56Z")

</div>

The back-and-forth can be a little frustrating, but it’s a sign that there’s people who really care and that we have an engaged community.

It’s FAR more frustrating to bring up an issue and get silence.

I’m going to chew on this for a while. I have some ideas that need more thought.

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [April 17, 2024, 3:59pm UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/24 "2024-04-17T15:59:34Z")

</div>

> [@Lily-Foote](#):
>
> An exception from `instance.save()` if the `name` is not set to a valid value (or at all) makes sense to me.

Sounds good to me. This does sound like something that should happen inside `FileField`, maybe in `get_db_prep_value()`.

---

<div class="post-metadata">

**Author:** ![john-parton](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/john-parton/32/20634_2.png) [@john-parton](https://forum.djangoproject.com/u/john-parton)\
**Post date:** [April 17, 2024, 9:37pm UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/25 "2024-04-17T21:37:57Z")

</div>

Thanks everyone for participating. I went ahead and created a bug report: [#35384 (Assigning a file without a name property to a FileField results in file getting discarded silently) – Django](https://code.djangoproject.com/ticket/35384#ticket)

I’ll see if I can put together a patch.

---

<div class="post-metadata">

**Author:** ![sarahboyce](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sarahboyce/32/12734_2.png) [@sarahboyce](https://forum.djangoproject.com/u/sarahboyce)\
**Post date:** [May 6, 2024, 8:14am UTC](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192/26 "2024-05-06T08:14:30Z")

</div>

This PR for the ticket looks good to me: [Fixed #35384 -- raise FieldError when trying to save ContentFile insta… by jonnythebard · Pull Request #18109 · django/django · GitHub](https://github.com/django/django/pull/18109/)  
As you were all quite deeply engaged with the discussion, feel free to have a look and check if this is what you were expecting. Including whether the wording of the error message is appropriate. 👍

[Previous page](https://forum.djangoproject.com/t/setting-filefield-imagefield-where-file-has-no-name/30192.md?page=1)
