Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r59TF-00C2dd-Ig for psycopg@arkaria.postgresql.org; Mon, 20 Nov 2023 18:58:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r59TE-009kma-1M for psycopg@arkaria.postgresql.org; Mon, 20 Nov 2023 18:58:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r59TD-009kmS-Pk for psycopg@lists.postgresql.org; Mon, 20 Nov 2023 18:58:07 +0000 Received: from mail-lj1-x229.google.com ([2a00:1450:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r59TA-007TcF-Ky for psycopg@postgresql.org; Mon, 20 Nov 2023 18:58:06 +0000 Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c6b30aca06so58390761fa.3 for ; Mon, 20 Nov 2023 10:58:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700506683; x=1701111483; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=UD9f8mKDDWulSlV+rCQDaIKFgvtzzK7jWTz0vmlQXeM=; b=i1bIAyOiqV5Sz5wYpKx2wyinlvD8ot6nFSYePJ5hPw2PohYK8UIEOCXgsSN3USX1r2 ysHt9IfRTOq/CdgkQyFf02DKFI/64Erb3wBVi8b+vE7VNT+yjoDzeli5EF89onTPRIwB L/fQ/Lsf9A+coCn5V2t5UtdlEzW6LqSjR6Q/M3K0R72at/F8kWjkXrqmhho2bKobjdr+ 75Jkhn2rAdjVJDrKHVdt4Q+Z4NwhpH/3ecD/wvVqnXrYA6bsePT3QBu/PC8NwqsZiAqn +DYLxJhwzTzXuvZl2ftSoHuTmSwVvq/P7fWNeYAisPU9o4IlreMESJyiV1xgn5qR6Eak 66aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700506683; x=1701111483; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=UD9f8mKDDWulSlV+rCQDaIKFgvtzzK7jWTz0vmlQXeM=; b=Kz1j3+62hDmaO0wPWkQC2rbtEsMClpy4C1JQ2V4Khw3a7b6ykjsOBko7ubCK60Z3/K B9l8fgojiPlswHqeCBcC+hjerQdq0Xg1MD77jSFyfRNk89ospe5MlpHIc6MyZEGr6eFb mHiIRK2+bbUfBbKT2wHSVA3KzbgZDUCO9VdIkWzm+aC/yHRy0bHBofxIXauk8D4ZkP5j TEqOj51VKeRmMo0REOxngYwFMA7yg+JUCMdy6ESzrskT5JpclMZiDPzTsbdgtXEBmhja BNk1RPh6WEPcVVEQaU6tiNBgfkmRpPvE8sWZnXy/kV2Ra3nnakCulWRRBpiYx4UbuFZU Hk3g== X-Gm-Message-State: AOJu0YyzixikG1BXK3rZH9ihj+fj4tAAHVRM/Vs/dehDFcGTZ4vfeyqC YlBOXb2k4US61XQF5w8X11+xtk0gosnFCobGqGZBzGLFVN0= X-Google-Smtp-Source: AGHT+IGn11MZY8LH84T6OmDWaSokIGK4Ri9BnUSOUKhCXSNwez0fSxZYgH/vnIuPKgF0JmQ7lFAqRQ3Vf3Jb0O2t1KU= X-Received: by 2002:a2e:924f:0:b0:2c8:73b7:5a1c with SMTP id v15-20020a2e924f000000b002c873b75a1cmr5562764ljg.3.1700506683427; Mon, 20 Nov 2023 10:58:03 -0800 (PST) MIME-Version: 1.0 From: Ams Fwd Date: Mon, 20 Nov 2023 10:57:52 -0800 Message-ID: Subject: 2-to-3 Question about adapter using AsIs To: psycopg@postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I am working on migrating our django codebase from ver 2 to ver 3+ and have run into a code conversion issue that I have not quite been able to figure out. Previously for a generated column in our schema (dealing with accented names) we used to have: from django.db import models from psycopg2.extensions import AsIs, register_adapter class PostgresDefaultValueType: pass register_adapter(PostgresDefaultValueType, lambda _: AsIs("DEFAULT")) class PostgresHandledTextField(models.TextField): def get_prep_value(self, value): return PostgresDefaultValueType() This was based off of a comment on a ticket (https://code.djangoproject.com/ticket/21454#comment:28) to be able to handle DEFAULT columns in postgres when using Django. Trying to convert this to psycopg3's updated adapter framework, what I have tried so far is this: from django.db import models from psycopg import adapters, sql from psycopg.adapt import Dumper class PostgresDefaultValueType: pass class PostgresDefaultValueTypeDumper(Dumper): def dump(self, obj): return sql.DEFAULT adapters.register_dumper(PostgresDefaultValueType, PostgresDefaultValueTypeDumper) class PostgresHandledTextField(models.TextField): def get_prep_value(self, value): return PostgresDefaultValueType() As far as I can tell from the documentation the `sql.DEFAULT` should be the appropriate thing to put in the dumper so that generated query uses `'DEFAULT'` in the correct place during query generation. However when I do use this I run into > ??? E TypeError: bytes or buffer expected, got psycopg_binary/pq/pqbuffer.pyx:111: TypeError which in some ways makes sense as `AsIs` previously did something special and it's not the same? Looking at the code, it should merely be doing `PyUnicode_AsUTF8String` but I am assuming that `sql.DEFAULT` is not generating the appropriate quoted string? Any help in debugging this would be greatly appreciated TIA. AM