Uses object name in cannot distribute object error (#6186)

Object type ids have changed in PG15 because of at least two added
objects in the list: OBJECT_PARAMETER_ACL, OBJECT_PUBLICATION_NAMESPACE

To avoid different output between pg versions, let's use the object
name in the error, and put the object id in the error detail.

Relevant PG commits:
a0ffa885e478f5eeacc4e250e35ce25a4740c487
5a2832465fd8984d089e8c44c094e6900d987fcd
pull/6166/head
Naisila Puka 2022-08-18 11:05:17 +03:00 committed by GitHub
parent 91473635db
commit 69ffdbf0e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -34,7 +34,8 @@
#include "mb/pg_wchar.h"
#include "parser/parse_type.h"
static void ErrorIfCurrentUserCanNotDistributeObject(ObjectType type,
static void ErrorIfCurrentUserCanNotDistributeObject(char *textType,
ObjectType type,
ObjectAddress *addr,
Node *node,
Relation *relation);
@ -372,7 +373,7 @@ PgGetObjectAddress(char *ttype, ArrayType *namearr, ArrayType *argsarr)
&relation, AccessShareLock, false);
/* CITUS CODE BEGIN */
ErrorIfCurrentUserCanNotDistributeObject(type, &addr, objnode, &relation);
ErrorIfCurrentUserCanNotDistributeObject(ttype, type, &addr, objnode, &relation);
/* CITUS CODE END */
@ -394,14 +395,16 @@ PgGetObjectAddress(char *ttype, ArrayType *namearr, ArrayType *argsarr)
* distribute object, if not errors out.
*/
static void
ErrorIfCurrentUserCanNotDistributeObject(ObjectType type, ObjectAddress *addr,
Node *node, Relation *relation)
ErrorIfCurrentUserCanNotDistributeObject(char *textType, ObjectType type,
ObjectAddress *addr, Node *node,
Relation *relation)
{
Oid userId = GetUserId();
if (!SupportedDependencyByCitus(addr))
{
ereport(ERROR, (errmsg("Object type %d can not be distributed by Citus", type)));
ereport(ERROR, (errmsg("%s object can not be distributed by Citus", textType),
errdetail("Object type id is %d", type)));
}
switch (type)

View File

@ -675,7 +675,7 @@ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
WITH distributed_object_data(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation)
AS (VALUES ('publication', ARRAY['publication_test']::text[], ARRAY[]::text[], -1, 0, false))
SELECT citus_internal_add_object_metadata(typetext, objnames, objargs, distargumentindex, colocationid, force_delegation) FROM distributed_object_data;
ERROR: Object type 29 can not be distributed by Citus
ERROR: publication object can not be distributed by Citus
ROLLBACK;
-- Show that citus_internal_add_object_metadata checks the priviliges
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;