Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some examples appear to always ERROR #382

Open
workingjubilee opened this issue Sep 10, 2023 · 4 comments
Open

Some examples appear to always ERROR #382

workingjubilee opened this issue Sep 10, 2023 · 4 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@workingjubilee
Copy link
Contributor

e.g.

CREATE OR REPLACE FUNCTION plrust.random_slogan() RETURNS TEXT
LANGUAGE plrust AS $$
[dependencies]
    faker_rand = "0.1"
    rand = "0.8"
[code]
    use faker_rand::en_us::company::Slogan;
    Ok(Some(rand::random::<Slogan>().to_string()))
$$;

SELECT plrust.random_slogan();

reportedly yields

CREATE FUNCTION
ERROR:  cannot sample empty range

which hits an assert here:

    fn gen_range<T, R>(&mut self, range: R) -> T
    where
        T: SampleUniform,
        R: SampleRange<T>
    {
        assert!(!range.is_empty(), "cannot sample empty range");
        range.sample_single(self).unwrap()
    }
@workingjubilee workingjubilee added bug Something isn't working documentation Improvements or additions to documentation labels Sep 10, 2023
@gaslitbytech
Copy link

I created a test in plrust-tests/src/dependencies.rs that I wanted to use to reproduce the issue.

Though I did get:

   0: `faker_rand` is not an allowed dependency

New Test:

    #[pg_test]
    #[cfg(not(feature = "sandboxed"))]
    #[search_path(@extschema@)]
    fn plrust_deps_docs() -> spi::Result<()> {
        let definition = r#"
        CREATE OR REPLACE FUNCTION plrust.random_company_name(locale TEXT)
            RETURNS TEXT
            LANGUAGE plrust STRICT
        AS $$
        [dependencies]
            faker_rand = "0.1"
            rand = "0.8"
        [code]
            match locale {
                "en_us" => {
                    use faker_rand::en_us::company::CompanyName;
                    Ok(Some(rand::random::<CompanyName>().to_string()))
                }
                "fr_fr" => {
                    use faker_rand::fr_fr::company::CompanyName;
                    Ok(Some(rand::random::<CompanyName>().to_string()))
                }
                _ => panic!("Unsupported locale. Use en_us or fr_fr")
            }
        $$;    
        "#;
        Spi::run(definition)?;

        let retval = Spi::get_one::<String>(
            r#"
            SELECT plrust.random_company_name('fr_fr') AS fr_fr;        
        "#
        );
        assert!(retval.is_ok());
        assert!(retval.unwrap().is_some());
        Ok(())
    }

Full Error:

Client Error:

   0: `faker_rand` is not an allowed dependency

Location:
   plrust/src/user_crate/mod.rs:351

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   0: plrust::user_crate::parse_source_and_deps
      at plrust/src/user_crate/mod.rs:308
   1: plrust::user_crate::crating::try_from_fn_oid with db_oid=Oid(16384) fn_oid=Oid(16481)
      at plrust/src/user_crate/crating.rs:59
   2: plrust::user_crate::try_from_fn_oid
      at plrust/src/user_crate/mod.rs:103
   3: plrust::plrust::compile_function with fn_oid=Oid(16481)
      at plrust/src/plrust.rs:100
   4: plrust::plrust_validator with fn_oid=Oid(16481) fcinfo=0x7fffe3ab9cd0
      at plrust/src/lib.rs:225

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
postgres location: lib.rs
rust location: SQL statement "
        CREATE OR REPLACE FUNCTION plrust.random_company_name(locale TEXT)
            RETURNS TEXT
            LANGUAGE plrust STRICT
        AS $$
        [dependencies]
            faker_rand = "0.1"
            rand = "0.8"
        [code]
            match locale {
                "en_us" => {
                    use faker_rand::en_us::company::CompanyName;
                    Ok(Some(rand::random::<CompanyName>().to_string()))
                }
                "fr_fr" => {
                    use faker_rand::fr_fr::company::CompanyName;
                    Ok(Some(rand::random::<CompanyName>().to_string()))
                }
                _ => panic!("Unsupported locale. Use en_us or fr_fr")
            }
        $$;    
        "

', /home/david/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pgrx-tests-0.10.0/src/framework.rs:172:9


failures:
    dependencies::tests::pg_plrust_deps_docs

test result: FAILED. 48 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 268.83s

Is this related to trusted / untrusted mode?

@workingjubilee
Copy link
Contributor Author

The tests are set up with an allowed dependencies file here:

allowed_deps
.write_all(
r#"
owo-colors = "=3.5.0"
tokio = { version = "=1.19.2", features = ["rt", "net"]}
plutonium = "*"
"#

@gaslitbytech
Copy link

gaslitbytech commented Sep 10, 2023

Thanks. Interesting that the test still passes.

So I changed

        assert!(retval.is_ok());
        assert!(retval.unwrap().is_some());

To

        assert_eq!(retval, Ok(Some("Is this a random french company name.".to_string())));

And now I get:

Client Error:
assertion failed: `(left == right)`
 left: `Ok(Some("Agathange EI"))`,
right: `Ok(Some("Is this a random french company name."))`
postgres location: dependencies.rs

So this means that this example does work in the unit tests. Just not when I launch using Dockerfile.try

@workingjubilee
Copy link
Contributor Author

That's weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants