Skip to content

Commit 4ab3297

Browse files
committed
Make lantern_extras prefix reserved in pgrx
Make sure MarkGUCPrefix is only used in pg15 and pg16
1 parent 1257c10 commit 4ab3297

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

lantern_extras/src/lib.rs

+26
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ pub unsafe extern "C" fn _PG_init() {
148148
GucContext::Userset,
149149
GucFlags::NO_SHOW_ALL,
150150
);
151+
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
152+
unsafe {
153+
use pg_sys::AsPgCStr;
154+
pg_sys::MarkGUCPrefixReserved("lantern_extras".as_pg_cstr());
155+
}
151156
}
152157

153158
#[pg_guard]
@@ -245,3 +250,24 @@ pub mod pg_test {
245250
]
246251
}
247252
}
253+
254+
#[cfg(any(test, feature = "pg_test"))]
255+
#[pg_schema]
256+
pub mod tests {
257+
258+
// note: this will not get to unwrap, since the failure in the result only represents
259+
// failures in the SPI machinery.
260+
// Postgres aborts the transaction and returns an error message to the client when the SPI
261+
// query fails. So, the rust interface has no Error representation for a failed query.
262+
// As a last resort we can ensure the test panics with the expected message.
263+
// https://www.postgresql.org/docs/current/spi.html
264+
265+
#[cfg(any(feature = "pg15", feature = "pg16", feature = "pg17"))]
266+
#[pgrx::pg_test]
267+
#[should_panic(expected = "invalid configuration parameter name")]
268+
fn lantern_extras_prefix_reserved() {
269+
use pgrx::{error, Spi};
270+
Spi::run("SET lantern_extras.aldkjalsdkj_invalid_param = 42").unwrap();
271+
error!("Managed to update a reserved-prefix variable. This should never be reached");
272+
}
273+
}

0 commit comments

Comments
 (0)