termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
35.16k stars 3.7k forks source link

python django OSError #4081

Closed shaheen-coder closed 1 month ago

shaheen-coder commented 1 month ago

Problem description

in python django 5.0.7, native termux cant work with file handling thought django and same django project work good on proot-distro ubuntu

error :

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

in settings.py add :

STATIC_URL = 'static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

then run command python manage.py collectstatic you will get this OSError

Steps to reproduce the behavior.

i dont know

What is the expected behavior?

No response

System information

Termux Variables: TERMUX_API_VERSION=0.50.1 TERMUX_APK_RELEASE=F_DROID TERMUX_APP_PACKAGE_MANAGER=apt TERMUX_APP_PID=9887 TERMUX_IS_DEBUGGABLE_BUILD=0 TERMUX_MAIN_PACKAGE_FORMAT=debian TERMUX_VERSION=0.118.0 TERMUX__USER_ID=0 Packages CPU architecture: aarch64 Subscribed repositories:

sources.list

deb https://packages-cf.termux.dev/apt/termux-main stable main

sources.list.d/pointless.list

deb https://its-pointless.github.io/files/21 termux extras

x11-repo (sources.list.d/x11.list)

deb https://packages-cf.termux.dev/apt/termux-x11 x11 main termux-tools version: 1.42.2 Android version: 12 Kernel build information: Linux localhost 4.19.191-perf-01022-gec293e668c0c #1 SMP PREEMPT Fri Mar 10 18:54:33 CST 2023 aarch64 Android Device manufacturer: Xiaomi Device model: 22120RN86G LD Variables: LD_LIBRARY_PATH= LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so Installed termux plugins: com.termux.api versionCode:51 com.termux.x11 versionCode:14

shaheen-coder commented 1 month ago

I figured it out,django file handling works on home dir but not on other dir because of Android os