Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activation of session after deletion raises 500 error. #322

Open
GrahamDumpleton opened this issue Mar 19, 2024 · 1 comment
Open

Activation of session after deletion raises 500 error. #322

GrahamDumpleton opened this issue Mar 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@GrahamDumpleton
Copy link
Contributor

Describe the bug

When use /workshops/session/xxx/activate/ to activate a session on a training portal and the session had already expired the startup timeout and been deleted (or in process of being deleted), you can get a database integrity error which would result in a 500 error.

2024-03-18T22:20:17.597148968Z [Mon Mar 18 22:20:17.597085 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144] ERROR:django.request - Internal Server Error: /workshops/session/tanzu-gunter-w01-s001/activate/
2024-03-18T22:20:17.597164994Z [Mon Mar 18 22:20:17.597096 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144] Traceback (most recent call last):
2024-03-18T22:20:17.597166940Z [Mon Mar 18 22:20:17.597098 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
2024-03-18T22:20:17.597168519Z [Mon Mar 18 22:20:17.597100 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return self.cursor.execute(sql, params)
2024-03-18T22:20:17.597169726Z [Mon Mar 18 22:20:17.597101 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/sqlite3/base.py", line 423, in execute
2024-03-18T22:20:17.597170818Z [Mon Mar 18 22:20:17.597102 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return Database.Cursor.execute(self, query, params)
2024-03-18T22:20:17.597172076Z [Mon Mar 18 22:20:17.597103 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144] sqlite3.IntegrityError: FOREIGN KEY constraint failed
2024-03-18T22:20:17.597173785Z [Mon Mar 18 22:20:17.597104 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]
2024-03-18T22:20:17.597175234Z [Mon Mar 18 22:20:17.597105 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144] The above exception was the direct cause of the following exception:
2024-03-18T22:20:17.597176296Z [Mon Mar 18 22:20:17.597106 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]
2024-03-18T22:20:17.597177391Z [Mon Mar 18 22:20:17.597107 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144] Traceback (most recent call last):
2024-03-18T22:20:17.597178598Z [Mon Mar 18 22:20:17.597108 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
2024-03-18T22:20:17.597179644Z [Mon Mar 18 22:20:17.597110 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     response = get_response(request)
2024-03-18T22:20:17.597180633Z [Mon Mar 18 22:20:17.597111 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
2024-03-18T22:20:17.597182046Z [Mon Mar 18 22:20:17.597112 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
2024-03-18T22:20:17.597183240Z [Mon Mar 18 22:20:17.597113 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/views/decorators/http.py", line 40, in inner
2024-03-18T22:20:17.597184339Z [Mon Mar 18 22:20:17.597114 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return func(request, *args, **kwargs)
2024-03-18T22:20:17.597185484Z [Mon Mar 18 22:20:17.597115 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/src/project/apps/workshops/views/session.py", line 145, in session_activate
2024-03-18T22:20:17.597186750Z [Mon Mar 18 22:20:17.597116 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     instance.mark_as_running()
2024-03-18T22:20:17.597187867Z [Mon Mar 18 22:20:17.597117 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/src/project/apps/workshops/models.py", line 762, in mark_as_running
2024-03-18T22:20:17.597189241Z [Mon Mar 18 22:20:17.597118 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     self.save()
2024-03-18T22:20:17.597190440Z [Mon Mar 18 22:20:17.597119 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/base.py", line 739, in save
2024-03-18T22:20:17.597192626Z [Mon Mar 18 22:20:17.597121 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     self.save_base(using=using, force_insert=force_insert,
2024-03-18T22:20:17.597193842Z [Mon Mar 18 22:20:17.597122 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/base.py", line 776, in save_base
2024-03-18T22:20:17.597194993Z [Mon Mar 18 22:20:17.597123 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     updated = self._save_table(
2024-03-18T22:20:17.597196086Z [Mon Mar 18 22:20:17.597124 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/base.py", line 858, in _save_table
2024-03-18T22:20:17.597207115Z [Mon Mar 18 22:20:17.597126 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     updated = self._do_update(base_qs, using, pk_val, values, update_fields,
2024-03-18T22:20:17.597208306Z [Mon Mar 18 22:20:17.597127 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/base.py", line 912, in _do_update
2024-03-18T22:20:17.597209454Z [Mon Mar 18 22:20:17.597128 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return filtered._update(values) > 0
2024-03-18T22:20:17.597211629Z [Mon Mar 18 22:20:17.597130 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/query.py", line 802, in _update
2024-03-18T22:20:17.597212726Z [Mon Mar 18 22:20:17.597131 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return query.get_compiler(self.db).execute_sql(CURSOR)
2024-03-18T22:20:17.597213685Z [Mon Mar 18 22:20:17.597132 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
2024-03-18T22:20:17.597214753Z [Mon Mar 18 22:20:17.597133 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     cursor = super().execute_sql(result_type)
2024-03-18T22:20:17.597216028Z [Mon Mar 18 22:20:17.597135 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
2024-03-18T22:20:17.597217211Z [Mon Mar 18 22:20:17.597136 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     cursor.execute(sql, params)
2024-03-18T22:20:17.597218357Z [Mon Mar 18 22:20:17.597137 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 66, in execute
2024-03-18T22:20:17.597219558Z [Mon Mar 18 22:20:17.597138 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
2024-03-18T22:20:17.597220931Z [Mon Mar 18 22:20:17.597139 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
2024-03-18T22:20:17.597221973Z [Mon Mar 18 22:20:17.597141 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return executor(sql, params, many, context)
2024-03-18T22:20:17.597223208Z [Mon Mar 18 22:20:17.597142 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 79, in _execute
2024-03-18T22:20:17.597224246Z [Mon Mar 18 22:20:17.597143 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     with self.db.wrap_database_errors:
2024-03-18T22:20:17.597225418Z [Mon Mar 18 22:20:17.597144 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/utils.py", line 90, in __exit__
2024-03-18T22:20:17.597227853Z [Mon Mar 18 22:20:17.597146 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     raise dj_exc_value.with_traceback(traceback) from exc_value
2024-03-18T22:20:17.597228890Z [Mon Mar 18 22:20:17.597147 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
2024-03-18T22:20:17.597230006Z [Mon Mar 18 22:20:17.597148 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return self.cursor.execute(sql, params)
2024-03-18T22:20:17.597231004Z [Mon Mar 18 22:20:17.597149 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]   File "/opt/app-root/venv/lib64/python3.10/site-packages/django/db/backends/sqlite3/base.py", line 423, in execute
2024-03-18T22:20:17.597232277Z [Mon Mar 18 22:20:17.597151 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144]     return Database.Cursor.execute(self, query, params)
2024-03-18T22:20:17.597233364Z [Mon Mar 18 22:20:17.597152 2024] [wsgi:error] [pid 14:tid 37] [remote 10.0.3.79:35144] django.db.utils.IntegrityError: FOREIGN KEY constraint failed

Need to explore what is occurring and catch problem and return better error response.

Additional information

No response

@GrahamDumpleton GrahamDumpleton added the bug Something isn't working label Mar 19, 2024
@GrahamDumpleton
Copy link
Contributor Author

Possibly relates to use of on_delete=models.PROTECT in:

class Session(models.Model):
    name = models.CharField(
        verbose_name="session name", max_length=256, primary_key=True
    )
    id = models.CharField(verbose_name="session id", max_length=64)
    uid = models.CharField(verbose_name="resource uid", max_length=255, default="")
    environment = models.ForeignKey(Environment, on_delete=models.PROTECT)
    application = models.ForeignKey(
        Application, blank=True, null=True, on_delete=models.PROTECT
    )
    state = models.IntegerField(
        choices=SessionState.choices(), default=SessionState.STARTING
    )
    owner = models.ForeignKey(User, blank=True, null=True, on_delete=models.PROTECT)
    ...

Don't understand why exactly triggered as still need to test, but perhaps application and owner should use models.SET_NULL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

1 participant