question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

django.db.utils.DatabaseError: Forced update did not affect any rows.

See original GitHub issue

Please see the stack trace below.

I am not absolutely convinced this is a channels issue, but the stack trace makes it look like a channels issue. My interpretation of this (somewhat confusing) stack trace is that channels/sessions.py line 58 has the call to save() that is causing this error.

Unfortunately, it is somewhat random. In particular, when I start investigating the problem in detail, the problem tends to disappear.

Django version 1.11.5, Channels version 1.1.8.

Some sort of race condition maybe??? I have some rough theories, none of them exactly make any sense yet.

[2017-11-27 14:39:27,803: ERROR/django.channels] Error processing message with consumer myrocc.consumers.Demultiplexer:
Traceback (most recent call last):
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 87, in save
    obj.save(force_insert=must_create, force_update=not must_create, using=using)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 807, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 837, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 906, in _save_table
    raise DatabaseError("Forced update did not affect any rows.")
django.db.utils.DatabaseError: Forced update did not affect any rows.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 54, in inner
    return func(*args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/auth.py", line 42, in inner
    return func(message, *args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/generic/websockets.py", line 71, in raw_connect
    self.connect(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/generic/websockets.py", line 278, in connect
    consumer(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/generic/base.py", line 32, in __init__
    self.dispatch(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/generic/base.py", line 70, in dispatch
    return self.get_handler(message, **kwargs)(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 193, in inner
    return func(message, *args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/auth.py", line 73, in inner
    return func(message, *args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 58, in inner
    message.channel_session.save()
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 94, in save
    raise UpdateError
django.contrib.sessions.backends.base.UpdateError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 87, in save
    obj.save(force_insert=must_create, force_update=not must_create, using=using)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 807, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 837, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 906, in _save_table
    raise DatabaseError("Forced update did not affect any rows.")
django.db.utils.DatabaseError: Forced update did not affect any rows.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 78, in inner
    return func(*args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/auth.py", line 89, in inner
    return func(message, *args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 58, in inner
    message.channel_session.save()
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 94, in save
    raise UpdateError
django.contrib.sessions.backends.base.UpdateError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 87, in save
    obj.save(force_insert=must_create, force_update=not must_create, using=using)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 807, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 837, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/db/models/base.py", line 906, in _save_table
    raise DatabaseError("Forced update did not affect any rows.")
django.db.utils.DatabaseError: Forced update did not affect any rows.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/worker.py", line 119, in run
    consumer(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/generic/base.py", line 32, in __init__
    self.dispatch(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/generic/base.py", line 70, in dispatch
    return self.get_handler(message, **kwargs)(message, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 220, in inner
    result = func(message, *args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/auth.py", line 73, in inner
    return func(message, *args, **kwargs)
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/channels/sessions.py", line 82, in inner
    session.save()
  File "/Users/brianmay/.pyenv/versions/3.6.2/envs/myrocc/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 94, in save
    raise UpdateError
django.contrib.sessions.backends.base.UpdateError

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewgodwincommented, Nov 29, 2017

Honestly, it might be better to email django-developers or open an issue here to discuss so it’s more public as well.

0reactions
brianmaycommented, Dec 15, 2017

I am going to close this bug report. I very much suspect the test framework we were using was truncating the database while the test server process was still running and processing WebSocket requests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

21761 (Confused about "Forced update did not affect any rows.")
I have a DatabaseError("Forced update did not affect any rows.") (from model.save_base). I cannot reproduce the error; Manually running save(force_update) ...
Read more >
In Django, how can I prevent a "Save with update_fields did ...
Sometimes I get the following error on my "save" line ... raise DatabaseError("Save with update_fields did not affect any rows.") django.db.
Read more >
Handling "Save with update_fields did not affect any rows"
Hi, the model.save() arguments `force_update` and `update_fields` cause an explicit check if the update statement matched any rows.
Read more >
Django (1.5) login exception (Save with update_fields did not ...
Every once in a while, the login function throws an exception (DatabaseError: Save with update_fields did not affect any rows) and I'm
Read more >
Save with update_fields did not affect any rows (while ...
Coding example for the question Save with update_fields did not affect any rows (while changing class)-django.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found