-
-
Notifications
You must be signed in to change notification settings - Fork 579
Flash messages are cleared if a session delete is called #2277
Comments
Could it be related to this #2211 ? |
Hi @Mido-sys, thanks for the report. I am trying to reproduce the issue with the following steps:
My patch in the step 3 is: --- a/actions/books.go
+++ b/actions/books.go
@@ -108,11 +108,13 @@ func (v BooksResource) Create(c buffalo.Context) error {
return err
}
+ c.Session().Set("coupon", "HAPPY_SUMMER")
+ fmt.Println("session", c.Session().Session.Values)
// Get the DB connection from the context
tx, ok := c.Value("tx").(*pop.Connection)
if !ok {
return fmt.Errorf("no transaction found")
}
// Validate the data from the html form
verrs, err := tx.ValidateAndCreate(book)
@@ -129,6 +131,10 @@ func (v BooksResource) Create(c buffalo.Context) error {
// correct the input.
c.Set("book", book)
+ c.Flash().Add("danger", "Error coupon")
+ c.Session().Delete("coupon")
+ fmt.Println("session", c.Session().Session.Values)
+
return c.Render(http.StatusUnprocessableEntity, r.HTML("books/new.plush.html"))
}).Wants("json", func(c buffalo.Context) error {
return c.Render(http.StatusUnprocessableEntity, r.JSON(verrs)) So I think the second part of the patch is the same as you quoted: c.Flash().Add("danger", "Error coupon")
c.Session().Delete("coupon")
fmt.Println("session", c.Session().Session.Values)
return c.Render(http.StatusUnprocessableEntity, r.HTML("books/new.plush.html")) But could not reproduce your issue. The only different from your example is the status code returns. Off topic: Is there any reason that using |
My log for the
(I tested it with status code 200) and it looks like everything is ok. Could you please add your |
Hello @sio4 , thanks for checking this. Yes, I will create an example and link the repo here |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
This issue was closed because it has been stalled for 5 days with no activity. |
Hello,
It seems that flash messages are cleared after a session delete is called. We were able to isolate this issue when form sends a POST request and the page reloads.
If we remove the
c.Session().Delete("coupon")
then the flash messages get displayed on a page redirect. If we refresh the page and call the session delete code then flash messages are displayed.The current buffalo version is
v0.18.7
The text was updated successfully, but these errors were encountered: