Skip to content

Commit 9255eca

Browse files
fix: implement objfuncargs creation for plain object func in AlterFunctionStmt - fixes original-upstream-guc test
Co-Authored-By: Dan Lynch <[email protected]>
1 parent 83c129f commit 9255eca

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

packages/transform/src/transformers/v13-to-v14.ts

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -962,16 +962,26 @@ export class V13ToV14Transformer {
962962
}
963963

964964
if (node.func !== undefined) {
965-
const funcResult = this.transform(node.func as any, childContext);
966-
967-
if (funcResult && typeof funcResult === 'object') {
968-
let funcData = funcResult;
969-
if ('ObjectWithArgs' in funcResult) {
970-
funcData = funcResult.ObjectWithArgs;
965+
// Handle plain object func (not wrapped in ObjectWithArgs)
966+
if (typeof node.func === 'object' && !('ObjectWithArgs' in node.func) && 'objargs' in node.func) {
967+
const funcResult: any = {};
968+
969+
if ((node.func as any).objname !== undefined) {
970+
funcResult.objname = this.transform((node.func as any).objname, childContext);
971+
}
972+
973+
if ((node.func as any).objargs !== undefined) {
974+
funcResult.objargs = this.transform((node.func as any).objargs, childContext);
975+
976+
// Create objfuncargs from objargs for PG14
977+
funcResult.objfuncargs = Array.isArray((node.func as any).objargs)
978+
? (node.func as any).objargs.map((arg: any) => this.createFunctionParameterFromTypeName(arg))
979+
: [this.createFunctionParameterFromTypeName((node.func as any).objargs)];
971980
}
972981

973-
result.func = 'ObjectWithArgs' in funcResult ? { ObjectWithArgs: funcData } : funcData;
982+
result.func = funcResult;
974983
} else {
984+
const funcResult = this.transform(node.func as any, childContext);
975985
result.func = funcResult;
976986
}
977987
}
@@ -1710,24 +1720,44 @@ export class V13ToV14Transformer {
17101720
const shouldPreserveObjfuncargs = this.shouldPreserveObjfuncargs(context);
17111721
const shouldCreateObjfuncargsFromObjargs = this.shouldCreateObjfuncargsFromObjargs(context);
17121722

1723+
// Debug logging for AlterFunctionStmt context
1724+
if (context.parentNodeTypes && context.parentNodeTypes.includes('AlterFunctionStmt')) {
1725+
console.log('DEBUG AlterFunctionStmt ObjectWithArgs:', {
1726+
shouldCreateObjfuncargs,
1727+
shouldPreserveObjfuncargs,
1728+
shouldCreateObjfuncargsFromObjargs,
1729+
hasObjargs: !!result.objargs,
1730+
hasObjfuncargs: !!result.objfuncargs,
1731+
parentNodeTypes: context.parentNodeTypes
1732+
});
1733+
}
17131734

17141735
if (shouldCreateObjfuncargsFromObjargs && result.objargs) {
17151736
// Create objfuncargs from objargs (this takes priority over shouldCreateObjfuncargs)
1737+
if (context.parentNodeTypes && context.parentNodeTypes.includes('AlterFunctionStmt')) {
1738+
console.log('DEBUG AlterFunctionStmt: CREATING objfuncargs from objargs');
1739+
}
17161740

17171741
result.objfuncargs = Array.isArray(result.objargs)
17181742
? result.objargs.map((arg: any) => this.createFunctionParameterFromTypeName(arg))
17191743
: [this.createFunctionParameterFromTypeName(result.objargs)];
17201744

17211745
} else if (shouldCreateObjfuncargs) {
1746+
if (context.parentNodeTypes && context.parentNodeTypes.includes('AlterFunctionStmt')) {
1747+
console.log('DEBUG AlterFunctionStmt: CREATING empty objfuncargs');
1748+
}
17221749
result.objfuncargs = [];
17231750
} else if (result.objfuncargs !== undefined) {
17241751
if (shouldPreserveObjfuncargs) {
1752+
if (context.parentNodeTypes && context.parentNodeTypes.includes('AlterFunctionStmt')) {
1753+
console.log('DEBUG AlterFunctionStmt: PRESERVING objfuncargs');
1754+
}
17251755
result.objfuncargs = Array.isArray(result.objfuncargs)
17261756
? result.objfuncargs.map((item: any) => this.transform(item, context))
17271757
: [this.transform(result.objfuncargs, context)];
17281758
} else {
1729-
if (context.parentNodeTypes && context.parentNodeTypes.includes('AlterOwnerStmt')) {
1730-
console.log('DEBUG: DELETING objfuncargs because shouldPreserveObjfuncargs is false');
1759+
if (context.parentNodeTypes && context.parentNodeTypes.includes('AlterFunctionStmt')) {
1760+
console.log('DEBUG AlterFunctionStmt: DELETING objfuncargs because shouldPreserveObjfuncargs is false');
17311761
}
17321762
delete result.objfuncargs;
17331763
}

0 commit comments

Comments
 (0)