TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.53k stars 581 forks source link

Unable to open database file #3307

Closed Serkeliss closed 1 month ago

Serkeliss commented 1 month ago

Tandoor Version

1.5.19

Setup

Unraid

Reverse Proxy

Nginx Proxy Manager (NPM)

Other

No response

Bug description

I don't know exactly when it happened, but I attempted to log into my Tandoor instance and put a new recipe in, but I noticed that whenever I would attempt to access anything on my instance, I would get Server 500 errors throughout. I turned on debug mode and attempted the same thing and got a specific error every time I tried to access any resource at all. The error says "Unable to open database file". I think the last time I probably accessed my recipes on Tandoor may have been a few months ago so it isn't a regular thing, but I still perform updates on the instances fairly regularly so I have no idea when this may have been broken, but I'm willing to dig or look at ways that I can troubleshoot. My current instance was pretty much all defaults, so it's probably using sqlite as the database or whatever the built-in one is. I'm not that savvy when it comes to database work, but I'm willing to try.

I'll try to put any new information or logs out here as I find more, but I was hoping for something that might just be something I overlooked or something.

Relevant logs

Environment:

Request Method: POST
Request URL: https://recipes.domain.local/accounts/login/

Django Version: 4.2.15
Python Version: 3.12.5
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django.contrib.postgres',
 'oauth2_provider',
 'django_tables2',
 'corsheaders',
 'crispy_forms',
 'crispy_bootstrap4',
 'rest_framework',
 'rest_framework.authtoken',
 'django_cleanup.apps.CleanupConfig',
 'webpack_loader',
 'django_js_reverse',
 'hcaptcha',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'cookbook.apps.CookbookConfig',
 'treebeard',
 'debug_toolbar']
Installed Middleware:
['corsheaders.middleware.CorsMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'cookbook.helper.scope_middleware.ScopeMiddleware',
 'allauth.account.middleware.AccountMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']

Traceback (most recent call last):
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return super().execute(query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The above exception (unable to open database file) was the direct cause of the following exception:
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/decorators/debug.py", line 92, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/utils/decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/decorators/cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/views.py", line 168, in dispatch
    return super(LoginView, self).dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/views.py", line 95, in dispatch
    response = super(RedirectAuthenticatedUserMixin, self).dispatch(

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/views.py", line 123, in post
    response = self.form_valid(form)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/views.py", line 181, in form_valid
    return form.login(self.request, redirect_url=success_url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/forms.py", line 210, in login
    ret = perform_login(

  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/utils.py", line 166, in perform_login
    return _perform_login(request, login)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/utils.py", line 179, in _perform_login
    return resume_login(request, login)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/utils.py", line 205, in resume_login
    adapter.login(request, login.user)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/allauth/account/adapter.py", line 521, in login
    django_login(request, user)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/contrib/auth/__init__.py", line 118, in login
    request.session.cycle_key()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/contrib/sessions/backends/base.py", line 304, in cycle_key
    self.create()
    ^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/contrib/sessions/backends/db.py", line 54, in create
    self.save(must_create=True)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/contrib/sessions/backends/db.py", line 86, in save
    obj.save(
    ^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/base.py", line 814, in save
    self.save_base(
    ^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/base.py", line 877, in save_base
    updated = self._save_table(

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1020, in _save_table
    results = self._do_insert(

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1061, in _do_insert
    return manager._insert(

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/manager.py", line 87, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/query.py", line 1805, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/models/sql/compiler.py", line 1822, in execute_sql
    cursor.execute(sql, params)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 102, in execute
    return super().execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/recipes/venv/lib/python3.12/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
    return super().execute(query, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: OperationalError at /accounts/login/
Exception Value: unable to open database file
Serkeliss commented 1 month ago

In addition, if I try to do a database dump to a file (by using something like the manage.py export command), I get the following error: Unable to serialize database: no such column: oauth2_provider_application.hash_client_secret

vabene1111 commented 1 month ago

it looks like the migrations did not run, I think the field shown in the logs might be new. Have you made sure that when updating you ran all migrations? Not sure if that needs to be done manually on unraid

Serkeliss commented 1 month ago

That's a good question. I wasn't even aware of any manual migrations that needed to occur. I just had the unraid docker container being updated as it went along. Is there a knowledge base article or help file of any commands that need to be run in order to do these migrations?

I'm sorry if I'm speaking straight from inexperience or if this is even the right medium in order to report these issues. I just don't recall any necessary processes or things that were spelled out that I just didn't grasp. I'm more than willing to try anything that might lead to a better experience, though. I just didn't want to lose whatever recipes that I've already put in since it represented many hours of work already.

vabene1111 commented 1 month ago

so looking at the instructions I do not really see any indications that migrations would need to run manually but maybe they failed for some reason. Sadly I am not at all familiar with unraid so I cannot really help you a lot. You might want to join the discord and ask if anyone familiar with unraid is willing to lend you a hand and look at your problem.

One tip I can give you is that if the issue is related to migrations you should look at the log of the container when the container starts. It shows information about migrations and if they might have failed. Another thing, given the error message, might be file access (permissions) that you might look into.

Serkeliss commented 1 month ago

Trying to look at things again for the weekend. I've found that everything looks good on the permission side of things from the OS level, but it might be a database permission thing.

Is there some command that I can issue to the general database file (in my case it is recipes.db and still the SQLite3 backend)? Should I attempt to migrate it to a different backend? Is it possible to do that with it in this state? If I wanted to just export my recipes out of the database, it is possible to just grant it a full root r/w permissions for everyone temporarily, export my recipes, and then start over another instance from scratch? What would be a good way to do that?

vabene1111 commented 1 month ago

I am honestly not sure if sqlite even has permissions as its just a file, so I dont think its any database internal issue. Generally it is not advised running on sqlite as you miss out on some nice DB features, on the other hand people have migrated and from what I have heard its not a very pleasant thing to do (there are tutorials I think either here on GitHub in the discussions or in the docs, not entirely sure).

Still sqlite should work on unraid, maybe, trough looking at the commits, you can find out who contributed the unraid docs a while ago, I remember he was a pretty helpful and nice guy (?!), maybe he can help figure out whats wrong.

vabene1111 commented 1 month ago

what you can do, which would still loose you some data, is copy the sqlite DB, install tandoor just on your normal PC/mac, load it up and do a recipe export. You will loose some of the more special data (like food recipes, shopping lists, meal plans, ..) but at least have all your recipes.

Serkeliss commented 1 month ago

Thank you so much for your help with this. This was definitely NOT a Tandoor problem. I was thinking this was a problem with some migration or upgrade or breaking update that went amiss, but that was not what was going on. This was a specific Unraid problem, so you were spot on, vabene1111. It had to do with a weird storage pool rename that had occurred that was causing an issue on the Unraid side not to be able to map the storage correctly over to the docker instance, which was causing a permission issue on the appdata array that was accessible to the docker instance. Everything looks good now after I had a little time to work on it. I'm going to mark this case as closed, but since it didn't really have anything to do with Tandoor, you could probably just delete it or get rid of it. I appreciate your insight. It was extremely helpful!