~petersanchez/public-inbox

django-impersonate: Fixing the handling of user models that have a UUID primary key v1 APPLIED

=?iso-8859-1?q?Adam_Taylor?=: 1
 Fixing the handling of user models that have a UUID primary key

 1 files changed, 5 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.code.netlandish.com/~petersanchez/public-inbox/patches/120/mbox | git am -3
Learn more about email & git

[PATCH django-impersonate] Fixing the handling of user models that have a UUID primary key Export this patch

# HG changeset patch
# User Adam Taylor <ataylor32@gmail.com>
# Date 1743433368 0
#      Mon Mar 31 15:02:48 2025 +0000
# Node ID b536d2d35e1dac51f35580254f65a7ee30613138
# Parent  33cb8c77262a474869ab94bcb82c5446baf3c228
Fixing the handling of user models that have a UUID primary key

diff --git a/impersonate/views.py b/impersonate/views.py
--- a/impersonate/views.py
+++ b/impersonate/views.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import logging
from datetime import datetime, timezone
from uuid import UUID

from django.db.models import Q
from django.http import Http404
@@ -40,7 +41,10 @@
        logger.error(f'views/impersonate: Invalid value for uid given: {uid}')
        raise Http404('Invalid value given.')
    if check_allow_for_user(request, new_user):
        request.session['_impersonate'] = new_user.pk
        if isinstance(new_user.pk, UUID):
            request.session['_impersonate'] = str(new_user.pk)
        else:
            request.session['_impersonate'] = new_user.pk
        request.session['_impersonate_start'] = datetime.now(
            tz=timezone.utc
        ).timestamp()
Applied. Thanks!