From 4c5aca2d5e754911969831a658d511fa53bdfe03 Mon Sep 17 00:00:00 2001
From: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Date: Tue, 5 May 2026 01:13:18 +0530
Subject: [PATCH v1] Clean up property graph error messages

check_element_properties() saved a ReleaseSysCache() call until after
ereport(ERROR), making the explicit release unreachable.  Copy the
catalog fields needed for the error message and release the syscache
entry before building and reporting the error.

Also fix the wording of a property graph label consistency error from
"mismatching properties names" to "mismatching property names", and
update the matching expected output.
---
 src/backend/commands/propgraphcmds.c               | 14 +++++++++-----
 .../regress/expected/create_property_graph.out     |  4 ++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/backend/commands/propgraphcmds.c b/src/backend/commands/propgraphcmds.c
index 6d509fccf46..7784dd0f5c5 100644
--- a/src/backend/commands/propgraphcmds.c
+++ b/src/backend/commands/propgraphcmds.c
@@ -1113,6 +1113,8 @@ check_element_properties(Oid peoid)
 						HeapTuple	tuple3;
 						Form_pg_propgraph_element elform;
 						List	   *dpcontext;
+						char	   *element_name;
+						Oid			element_relid;
 						char	   *dpa,
 								   *dpb;
 
@@ -1120,7 +1122,11 @@ check_element_properties(Oid peoid)
 						if (!tuple3)
 							elog(ERROR, "cache lookup failed for property graph element %u", peoid);
 						elform = (Form_pg_propgraph_element) GETSTRUCT(tuple3);
-						dpcontext = deparse_context_for(get_rel_name(elform->pgerelid), elform->pgerelid);
+						element_name = pstrdup(NameStr(elform->pgealias));
+						element_relid = elform->pgerelid;
+						ReleaseSysCache(tuple3);
+
+						dpcontext = deparse_context_for(get_rel_name(element_relid), element_relid);
 
 						dpa = deparse_expression(na, dpcontext, false, false);
 						dpb = deparse_expression(nb, dpcontext, false, false);
@@ -1141,10 +1147,8 @@ check_element_properties(Oid peoid)
 						ereport(ERROR,
 								errcode(ERRCODE_SYNTAX_ERROR),
 								errmsg("element \"%s\" property \"%s\" expression mismatch: %s vs. %s",
-									   NameStr(elform->pgealias), get_propgraph_property_name(propoid), dpa, dpb),
+									   element_name, get_propgraph_property_name(propoid), dpa, dpb),
 								errdetail("In a property graph element, a property of the same name has to have the same expression in each label."));
-
-						ReleaseSysCache(tuple3);
 					}
 
 					break;
@@ -1266,7 +1270,7 @@ check_element_label_properties(Oid ellabeloid)
 	if (diff1 || diff2)
 		ereport(ERROR,
 				errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-				errmsg("mismatching properties names in definition of label \"%s\"", get_propgraph_label_name(labelid)));
+				errmsg("mismatching property names in definition of label \"%s\"", get_propgraph_label_name(labelid)));
 }
 
 /*
diff --git a/src/test/regress/expected/create_property_graph.out b/src/test/regress/expected/create_property_graph.out
index bc9a596ec89..bfa6712b365 100644
--- a/src/test/regress/expected/create_property_graph.out
+++ b/src/test/regress/expected/create_property_graph.out
@@ -210,11 +210,11 @@ CREATE PROPERTY GRAPH gx
         t1 KEY (a) LABEL l1 PROPERTIES (a, b),
         t2 KEY (i) LABEL l1 PROPERTIES (i AS a, j AS j)  -- mismatching property names on label
     );
-ERROR:  mismatching properties names in definition of label "l1"
+ERROR:  mismatching property names in definition of label "l1"
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS yy, b AS zz);  -- mismatching number of properties on label
 ERROR:  mismatching number of properties in definition of label "t3l1"
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x, b AS zz);  -- mismatching property names on label
-ERROR:  mismatching properties names in definition of label "t3l1"
+ERROR:  mismatching property names in definition of label "t3l1"
 ALTER PROPERTY GRAPH g4 ALTER VERTEX TABLE t1 ADD LABEL t3l1 PROPERTIES (a AS x);  -- mismatching number of properties on label
 ERROR:  mismatching number of properties in definition of label "t3l1"
 ALTER PROPERTY GRAPH g1 OWNER TO regress_graph_user1;
-- 
2.34.1

