diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c
index 7c627eacfb..69359908f8 100644
--- a/src/pl/plpython/plpy_elog.c
+++ b/src/pl/plpython/plpy_elog.c
@@ -103,11 +103,11 @@ PLy_elog_impl(int elevel, const char *fmt,...)
 		}
 		primary = emsg.data;
 
-		/* Since we have a format string, we cannot have a SPI detail. */
-		Assert(detail == NULL);
-
-		/* If there's an exception message, it goes in the detail. */
-		if (xmsg)
+		/*
+		 * When we have no detail from the error data, an exception message,
+		 * if not empty, goes in the detail.
+		 */
+		if (detail == NULL && xmsg != NULL)
 			detail = xmsg;
 	}
 	else
