From f10f70ef6060173615367459f19e763c738fb3e4 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Thu, 5 Oct 2023 17:40:40 -0700 Subject: [PATCH] Don't fail if 'id' is missing from an object. The goal here is to give us the freedom to drop 'id' from FreeObject. --- edgedb/datatypes/object.c | 12 ++++-------- tests/datatypes/test_datatypes.py | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/edgedb/datatypes/object.c b/edgedb/datatypes/object.c index 3e0050e2f..a2b1b03a0 100644 --- a/edgedb/datatypes/object.c +++ b/edgedb/datatypes/object.c @@ -51,13 +51,6 @@ EdgeObject_New(PyObject *desc) return NULL; } - if (EdgeRecordDesc_IDPos(desc) < 0) { - PyErr_SetString( - PyExc_ValueError, - "Cannot create Object without 'id' field"); - return NULL; - } - Py_ssize_t size = EdgeRecordDesc_GetSize(desc); if (size > EDGE_MAX_TUPLE_SIZE) { @@ -137,7 +130,10 @@ EdgeObject_GetID(PyObject *ob) assert(EdgeObject_Check(ob)); EdgeObject *o = (EdgeObject *)ob; Py_ssize_t i = EdgeRecordDesc_IDPos(o->desc); - if (i < 0 || i >= Py_SIZE(o)) { + if (i < 0) { + Py_RETURN_NONE; + } + if (i >= Py_SIZE(o)) { PyErr_BadInternalCall(); return NULL; } diff --git a/tests/datatypes/test_datatypes.py b/tests/datatypes/test_datatypes.py index 741489d46..93bbcd175 100644 --- a/tests/datatypes/test_datatypes.py +++ b/tests/datatypes/test_datatypes.py @@ -561,8 +561,8 @@ def test_object_5(self): lb='link-property', c='property' ) - with self.assertRaisesRegex(ValueError, "without 'id' field"): - f(1, 2, 3) + x = f(1, 2, 3) + self.assertFalse(hasattr(x, 'id')) def test_object_6(self): User = private.create_object_factory(