Also, I should have pointed out that ExecInsert doesn't actually check the partitin constraint except in very specific cases; what it does is expect that the partition routing code got it right. So the comment you're adding about that is wrong, and it did misled me into changing your code in a way that actually caused a bug -- hence my proposed rewording.
-- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services