Setting FileField/ImageField where file has no name

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?

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.)

Sounds sensible to me.

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.

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

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

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

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
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. :+1:

1 Like