# OSError : media upload error

**URL:** <https://forum.djangoproject.com/t/oserror-media-upload-error/33547>\
**Category:** Mystery Errors\
**Created:** [August 4, 2024, 8:40am UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547 "2024-08-04T08:40:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaheen-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shaheen-coder/32/23038_2.png) [@shaheen-coder](https://forum.djangoproject.com/u/shaheen-coder)\
**Post date:** [August 4, 2024, 8:40am UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/1 "2024-08-04T08:40:06Z")

</div>

error :

```auto
Internal Server Error: /admin/core/profile/aEfUZ89qMeZ2SpWdLPYVJS/change/
Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/storage/filesystem.py", line 109, in _save
    locks.lock(fd, locks.LOCK_EX)
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/locks.py", line 121, in lock
    fcntl.flock(_fd(f), flags)
OSError: [Errno 38] Function not implemented

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 716, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/sites.py", line 240, in inner
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1948, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1804, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1855, in _changeform_view
    self.save_model(request, new_object, form, not add)
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1259, in save_model
    obj.save()
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 822, in save
    self.save_base(
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 909, in save_base
    updated = self._save_table(
              ^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 1031, in _save_table
    values = [
             ^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 1035, in <listcomp>
    (getattr(self, f.attname) if raw else f.pre_save(self, False)),
                                          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/fields/files.py", line 317, in pre_save
    file.save(file.name, file.file, save=False)
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/fields/files.py", line 93, in save
    self.name = self.storage.save(name, content, max_length=self.field.max_length)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/storage/base.py", line 38, in save
    name = self._save(name, content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/storage/filesystem.py", line 116, in _save
    locks.unlock(fd)
  File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/locks.py", line 127, in unlock
    fcntl.flock(_fd(f), fcntl.LOCK_UN)
OSError: [Errno 38] Function not implemented

```

`settings.py` :

```auto
MEDIA_URL = '/media/' 
MEDIA_ROOT = BASE_DIR / 'media'

```

`models.py` :

```auto
def profile_path(instance,filename):
    return f'user-{instance.user.username}/profile/{filename}'
class Profile(models.Model):
    uuid = models.CharField(primary_key=True,max_length=22,default=shortuuid.uuid,editable=False)
    user = models.OneToOneField(User,on_delete=models.CASCADE)
    uname = models.CharField(max_length=20)
    profile_pic = models.ImageField(upload_to='profile/')
    def __str__ (self):
        return self.uname

```

---

<div class="post-metadata">

**Author:** ![onyeibo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/onyeibo/32/11494_2.png) [@onyeibo](https://forum.djangoproject.com/u/onyeibo)\
**Post date:** [August 4, 2024, 6:41pm UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/2 "2024-08-04T18:41:39Z")

</div>

> [@shaheen-coder](#):
>
> `profile_pic = models.ImageField(upload_to='profile/')`

That line … it appears you forgot to apply `profile_path` function object. Like so  
`profile_pic = models.ImageField(upload_to=profile_path)`

---

<div class="post-metadata">

**Author:** ![shaheen-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shaheen-coder/32/23038_2.png) [@shaheen-coder](https://forum.djangoproject.com/u/shaheen-coder)\
**Post date:** [August 5, 2024, 2:49am UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/3 "2024-08-05T02:49:58Z")

</div>

That’s not a problem man !!  
I can’t save model with that `ImageField` it throwing error `OSError` even i tried to save them on admin page !

---

<div class="post-metadata">

**Author:** ![onyeibo](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/onyeibo/32/11494_2.png) [@onyeibo](https://forum.djangoproject.com/u/onyeibo)\
**Post date:** [August 5, 2024, 3:34am UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/4 "2024-08-05T03:34:05Z")

</div>

try:

```auto
pip uninstall -y django
pip install django

```

Otherwise the traceback is missing out some lines that could identify the source of the error

---

<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:** [August 5, 2024, 3:54am UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/5 "2024-08-05T03:54:05Z")

</div>

Welcome @shaheen-coder !

Let’s take a step back and cover some basics.

What version of Django are you using?

Are you using any custom storage backends?

Is this your development environment or a production environment?

How are you running your project?

---

<div class="post-metadata">

**Author:** ![shaheen-coder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shaheen-coder/32/23038_2.png) [@shaheen-coder](https://forum.djangoproject.com/u/shaheen-coder)\
**Post date:** [August 5, 2024, 5:22am UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/6 "2024-08-05T05:22:30Z")

</div>

hi @KenWhitesell  
im using current version `5.0.7` on linux `4.19` kernel  
and i ain’t using any custom backend storage  
this is not a production code just a prototype.  
that error coming from django/core/files/lock `locks.py`  
i guess its sort of django framework bug

this model migrations and migrate run without any error or caution  
and i tried to add data through admin page then i getting this error

---

<div class="post-metadata">

**Author:** ![anefta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/anefta/32/10649_2.png) [@anefta](https://forum.djangoproject.com/u/anefta)\
**Post date:** [August 5, 2024, 1:06pm UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/7 "2024-08-05T13:06:29Z")

</div>

> [@shaheen-coder](#):
>
> error :
> 
> ```auto
> Internal Server Error: /admin/core/profile/aEfUZ89qMeZ2SpWdLPYVJS/change/
> Traceback (most recent call last):
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/storage/filesystem.py", line 109, in _save
> locks.lock(fd, locks.LOCK_EX)
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/locks.py", line 121, in lock
> fcntl.flock(_fd(f), flags)
> OSError: [Errno 38] Function not implemented
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
> response = get_response(request)
> ^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 716, in wrapper
> return self.admin_site.admin_view(view)(*args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
> result = _process_exception(request, e)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
> response = view_func(request, *args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
> response = view_func(request, *args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/sites.py", line 240, in inner
> return view(request, *args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1948, in change_view
> return self.changeform_view(request, object_id, form_url, extra_context)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 48, in _wrapper
> return bound_method(*args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
> result = _process_exception(request, e)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
> response = view_func(request, *args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1804, in changeform_view
> return self._changeform_view(request, object_id, form_url, extra_context)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1855, in _changeform_view
> self.save_model(request, new_object, form, not add)
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/contrib/admin/options.py", line 1259, in save_model
> obj.save()
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 822, in save
> self.save_base(
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 909, in save_base
> updated = self._save_table(
> ^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 1031, in _save_table
> values = [
> ^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/base.py", line 1035, in <listcomp>
> (getattr(self, f.attname) if raw else f.pre_save(self, False)),
> ^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/fields/files.py", line 317, in pre_save
> file.save(file.name, file.file, save=False)
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/db/models/fields/files.py", line 93, in save
> self.name = self.storage.save(name, content, max_length=self.field.max_length)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/storage/base.py", line 38, in save
> name = self._save(name, content)
> ^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/storage/filesystem.py", line 116, in _save
> locks.unlock(fd)
> File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/django/core/files/locks.py", line 127, in unlock
> fcntl.flock(_fd(f), fcntl.LOCK_UN)
> OSError: [Errno 38] Function not implemented
> 
> ```
> 
> `settings.py` :
> 
> ```auto
> MEDIA_URL = '/media/' 
> MEDIA_ROOT = BASE_DIR / 'media'
> 
> ```
> 
> `models.py` :
> 
> ```auto
> def profile_path(instance,filename):
> return f'user-{instance.user.username}/profile/{filename}'
> class Profile(models.Model):
> uuid = models.CharField(primary_key=True,max_length=22,default=shortuuid.uuid,editable=False)
> user = models.OneToOneField(User,on_delete=models.CASCADE)
> uname = models.CharField(max_length=20)
> profile_pic = models.ImageField(upload_to='profile/')
> def __str__ (self):
> return self.uname
> 
> ```

Show your code: model, view and admin.py

---

<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:** [August 5, 2024, 1:13pm UTC](https://forum.djangoproject.com/t/oserror-media-upload-error/33547/8 "2024-08-05T13:13:13Z")

</div>

> [@shaheen-coder](#):
>
> this model migrations and migrate run without any error or caution

These items have little (if anything) to do with uploading files. Uploaded files are not stored in the database. Only the file name is stored in the database.

> [@shaheen-coder](#):
>
> i guess its sort of django framework bug

Almost certainly not. Yes, it’s possible. However, that’s going to be the last conclusion I’d come to - once all other reasonable possibilities have been eliminated.

What operating system are you running this on?

How are you running your project?

What uid is running your code?

What are the permissions on the `BASE_DIR / 'media'` directory?
