askama icon indicating copy to clipboard operation
askama copied to clipboard

axum 0.8 is not compatible with askama_axum 0.5

Open networkhermit opened this issue 11 months ago • 2 comments

I tried to upgrade axum from 0.7.9 to 0.8.0, but it seems that the breaking changes introduced by axum also break askama_axum 0.5.

I managed to reproduce this issue within askama_axum:

-axum = { version = "0.7", default-features = false }
+axum = { version = "0.8", default-features = false }
❯ cargo test
   Compiling askama_axum v0.5.0 (/home/vac/Downloads/askama/askama_axum)
error[E0277]: the trait bound `fn() -> impl Future<Output = HelloTemplate<'static>> {hello}: Handler<_, _>` is not satisfied
   --> askama_axum/tests/basic.rs:23:44
    |
23  |     let app = Router::new().route("/", get(hello));
    |                                        --- ^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn() -> impl Future<Output = HelloTemplate<'static>> {hello}`
    |                                        |
    |                                        required by a bound introduced by this call
    |
    = note: Consider using `#[axum::debug_handler]` to improve the error message
    = help: the following other types implement trait `Handler<T, S>`:
              `Layered<L, H, T, S>` implements `Handler<T, S>`
              `MethodRouter<S>` implements `Handler<(), S>`
note: required by a bound in `axum::routing::get`
   --> /home/vac/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/axum-0.8.0/src/routing/method_routing.rs:440:1
    |
440 | top_level_handler_fn!(get, GET);
    | ^^^^^^^^^^^^^^^^^^^^^^---^^^^^^
    | |                     |
    | |                     required by a bound in this function
    | required by this bound in `get`
    = note: this error originates in the macro `top_level_handler_fn` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `askama_axum` (test "basic") due to 1 previous error

And bump the version of axum-core seems enough for this issue:

-axum-core = "0.4"
+axum-core = "0.5"
 http = "1.0"

 [dev-dependencies]
-axum = { version = "0.7", default-features = false }
+axum = { version = "0.8", default-features = false }
❯ cargo test
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.04s
     Running unittests src/lib.rs (/home/vac/Downloads/askama/target/debug/deps/askama_axum-f1829b4c98cc694b)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/basic.rs (/home/vac/Downloads/askama/target/debug/deps/basic-deeae636f21ff6a1)

running 1 test
test template_to_response ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests askama_axum

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

networkhermit avatar Jan 01 '25 15:01 networkhermit

Would it be possible to get this released as a patch for 0.12? Askama is now blocking all our renovate-bot PRs that uses axum and askama together, since askama can't build with axum 0.8

robert-sjoblom avatar Jan 27 '25 06:01 robert-sjoblom

I just published askama-derive-axum, which implements an IntoResponse derive macro which replaces the askama_axum crate which is slated for deprecation. It currently works with Askama 0.12 and axum-core 0.5 (aka axum 0.8).

use askama::Template;
use askama_derive_axum::IntoResponse;

#[derive(Template, IntoResponse)]
#[template(path = "index.html")]
struct IndexTemplate {
    title: String,
    body: String,
}

async fn index() -> IndexTemplate {
    IndexTemplate {
        title: "My Blog".to_string(),
        body: "Hello, world!".to_string(),
    }
}

joshka avatar Feb 20 '25 12:02 joshka