Received: from mail.netlandish.com (mail.netlandish.com [174.136.98.166])
	by code.netlandish.com (Postfix) with ESMTP id 45CE2A4
	for <~petersanchez/public-inbox@lists.code.netlandish.com>; Mon, 31 Mar 2025 15:13:18 +0000 (UTC)
Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.214.180; helo=mail-pl1-f180.google.com; envelope-from=ataylor32@gmail.com; receiver=<UNKNOWN> 
Authentication-Results: mail.netlandish.com;
	dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=abw7Lw/m
Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180])
	by mail.netlandish.com (Postfix) with ESMTP id E727A1D642E
	for <~petersanchez/public-inbox@lists.code.netlandish.com>; Mon, 31 Mar 2025 15:13:22 +0000 (UTC)
Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2240b4de12bso61337895ad.2
        for <~petersanchez/public-inbox@lists.code.netlandish.com>; Mon, 31 Mar 2025 08:13:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1743434001; x=1744038801; darn=lists.code.netlandish.com;
        h=to:from:date:user-agent:message-id:subject
         :content-transfer-encoding:mime-version:from:to:cc:subject:date
         :message-id:reply-to;
        bh=bQ6UAThy9Ic2kX7pfQwFCQUSi1ZSfUX7h3vUMLXmoUA=;
        b=abw7Lw/mw5/EXmLmabE+1sEA/uWGvZQd4Db+u+HRnrtJkiTn+96t45chSFQxDTbadt
         mMB5OayoohhT+MRXcQmkK1BT0Nyr5Iq9M/PcNbtrDEWjG2Y0QjOVKX5M3vTqC06vPFPi
         PHsmDt2MGIHHqMTWnIs/rgP3FizbNDM5SUt95Rv4euUR1Ei4zzmYkCJ5JxeZN0SAd8Fi
         yKg3miitot9OGkGYkKm8OsZM0h6DqugUmi8QX4vX97mJM5yz7yD0q6oIu4b5L7UT7Tb1
         E1+Oq1b0RLjWxp2EAqhCIADbjduzXQXAGcGhymwnwdDs3CdBbqtBqJBFT4koZt9xK1pa
         bxSA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1743434001; x=1744038801;
        h=to:from:date:user-agent:message-id:subject
         :content-transfer-encoding:mime-version:x-gm-message-state:from:to
         :cc:subject:date:message-id:reply-to;
        bh=bQ6UAThy9Ic2kX7pfQwFCQUSi1ZSfUX7h3vUMLXmoUA=;
        b=xJiuHv7FFkryX5PYbHp66Bs78uu4HpAbkV/geN2//e0qRc4qMJ3etLraXN3bGH2GBq
         pRtYFW+yEWBh7oaTlhdEa5lRpf++irP+lvYpGFyKOFoRH24CrvI/o8NLwsm9duQt6G9N
         ud0nHtXXm+zNBa6JUcdzV43yHax/0YZyfh6VxN9G4g/Uk4E5+uJNv5OXN3Klj3bP0tf6
         OxHiK4sxRb1JoihdTO0IRcxDNo0LrwTck5qb1cIs/pZ9A4xCSg+cMM4G8AIE5r2+ZdIS
         ahqBpymMZFkTgr49j7x2E3T+UoPvBuhRyesOcxEVBrE1H1yGaUxozH3Ve1Bx1VScdYpl
         4zLQ==
X-Gm-Message-State: AOJu0YxR54q8kZWzB2HYak/5Hu1G4VZi+n8H0gPinE2g6QH1PhvCuorG
	DvEHQCacz4VIonE4y14vcwIFy2YpkkHUd1lJBiIvM6HPGkAsaxHvMBpB7w==
X-Gm-Gg: ASbGncu2pKV/L255s9tqod5YX3tOsMwAuQqqCnihIqNJsJsiAViDac20hTs61GJIdg/
	6cHzj6MbSeIp1QNAVML1aWydjZ7YTup2zlaVef59zZBpQQ21NvmDvdYwlYXd3Sqju7+xo/a0DnS
	QNwLplWEGsaomw7WjZ2mH9AFFM1JnSzmJbn/vsquyKyQ+YtkuPpAQ4Mov9HPTEG05cwNmp7jZGO
	9HRUNZU9jaXkEW8n1mLKCJUF+/bOJHGD1uMKM5ejxsxz3zHpJ60IPmEtMgkq5BWt1+C4Pp34qx/
	/aRrhNmuqpzUsRZe/91TyIbGxmGb3kr4OUwncksQvoDRxr4zuBmJJ1x7IvCwKHXXe7UJSgRl3Jw
	DerQAfTVYB/7tNN18zZYRkbCOzms=
X-Google-Smtp-Source: AGHT+IEBHBonxHW5kIi5V8rkTICrahT+UGl9n7sXHMI8bj3Qz3cGpJmWKW3cbmp8+U/zuf2OFLaBEw==
X-Received: by 2002:a05:6a00:2e18:b0:736:a973:748 with SMTP id d2e1a72fcca58-739804484admr14061586b3a.22.1743434001038;
        Mon, 31 Mar 2025 08:13:21 -0700 (PDT)
Received: from [127.0.1.1] (h134-215-244-126.stgrut.broadband.dynamic.tds.net. [134.215.244.126])
        by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7397109c407sm7259489b3a.137.2025.03.31.08.13.20
        for <~petersanchez/public-inbox@lists.code.netlandish.com>
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 31 Mar 2025 08:13:20 -0700 (PDT)
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Subject: [PATCH django-impersonate] Fixing the handling of user models that
 have a UUID
 primary key
X-Mercurial-Node: b536d2d35e1dac51f35580254f65a7ee30613138
X-Mercurial-Series-Index: 1
X-Mercurial-Series-Total: 1
Message-Id: <b536d2d35e1dac51f355.1743433992@ted>
X-Mercurial-Series-Id: <b536d2d35e1dac51f355.1743433992@ted>
User-Agent: Mercurial-patchbomb/6.1.1
Date: Mon, 31 Mar 2025 15:13:12 +0000
From: =?iso-8859-1?q?Adam_Taylor?= <ataylor32@gmail.com>
To: ~petersanchez/public-inbox@lists.code.netlandish.com

# 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()

