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

Cannot force an update in save() with no primary key. #48

Closed
aclark4life opened this issue Jun 12, 2024 · 2 comments
Closed

Cannot force an update in save() with no primary key. #48

aclark4life opened this issue Jun 12, 2024 · 2 comments

Comments

@aclark4life
Copy link
Collaborator

aclark4life commented Jun 12, 2024

Hey all,

Not sure if you are looking for feedback, but FYI testing this with my Django setup and getting Cannot force an update in save() with no primary key. on update_fields = frozenset({'last_login'}).

False False frozenset({'last_login'})
Internal Server Error: /django/login/
Traceback (most recent call last):
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.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 "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/contrib/admin/sites.py", line 440, in login
    return LoginView.as_view(**defaults)(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/views/decorators/debug.py", line 143, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/utils/decorators.py", line 188, in _view_wrapper
    result = _process_exception(request, e)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/utils/decorators.py", line 186, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/utils/decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/views/decorators/cache.py", line 80, in _view_wrapper
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/contrib/auth/views.py", line 88, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/views/generic/edit.py", line 151, in post
    return self.form_valid(form)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/contrib/auth/views.py", line 107, in form_valid
    auth_login(self.request, form.get_user())
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/contrib/auth/__init__.py", line 152, in login
    user_logged_in.send(sender=user.__class__, request=request, user=user)
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/contrib/auth/models.py", line 23, in update_last_login
    user.save(update_fields=["last_login"])
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/contrib/auth/base_user.py", line 78, in save
    super().save(*args, **kwargs)
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 822, in save
    self.save_base(
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 909, in save_base
    updated = self._save_table(
              ^^^^^^^^^^^^^^^^^
  File "/Users/alexclark/Developer/test/test-django-mongodb/.venv/lib/python3.12/site-packages/django/db/models/base.py", line 1016, in _save_table
    raise ValueError("Cannot force an update in save() with no primary key.")
ValueError: Cannot force an update in save() with no primary key.
[12/Jun/2024 17:47:59] "POST /django/login/?next=/django/ HTTP/1.1" 500 286725
Not Found: /favicon.ico
[12/Jun/2024 17:47:59] "GET /favicon.ico HTTP/1.1" 404 15933

In the event this is not a known issue I'm interested in looking into it, if anyone would like to provide some feedback or direction. 😄 Thank you

@timgraham
Copy link
Collaborator

Hi Jeff, you will need to configure your project as per the additional instructions in #18.

@timgraham
Copy link
Collaborator

When you run into other issues, please create a new one or leave a comment here.

@timgraham timgraham closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants