I was a bit curious about the need for "set role" in the reproduction, but I see that it's because RI_Initial_Check does some checks to see if a simple SELECT can be used, and one of the checks is for basic table permissions.
I think to reproduce this the current user shouldn't be able to SELECT on both tables, so RI_Initial_Check fails. Setting the owner of one of the tables isn't always enough as the current user can be a super user.
I wonder if the macro RELKIND_HAS_STORAGE should be used instead of checking for each relkind? This would apply to the check on line 4405 too.
done.
This patch also changed the output of some of tests, i.e. previously foreign key constraint failures errored on the partitioned table itself, but now it shows the child table's name in the error message. I hope it is ok.
I also added a regression test which would fail without this patch.