GithubHelp home page GithubHelp logo

Comments (4)

workingjubilee avatar workingjubilee commented on August 22, 2024 1

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 = "*"
"#

from plrust.

workingjubilee avatar workingjubilee commented on August 22, 2024 1

That's weird.

from plrust.

gaslitbytech avatar gaslitbytech commented on August 22, 2024

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?

from plrust.

gaslitbytech avatar gaslitbytech commented on August 22, 2024

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

from plrust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.