Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Switching context from Dev to prod throws a generic "sql error" #2

Open
hubyhuby opened this issue Mar 8, 2018 · 0 comments
Open

Comments

@hubyhuby
Copy link

hubyhuby commented Mar 8, 2018

When deploying and setting your environment to Development.
I could get to see any page of my website. Wherease in development it was working.

This can be workedaround by deleting your cookies from the users browser.
When switshing back to dev after, the same behaviour arise.

The following erro is thrown in console mode, which is maybe a little too generic to find the problem:

ERRO[2018-03-08T11:18:32+01:00] sql: no rows in result set content_type=text/html db="3.158217ms" duration="7.859285ms" human_size="0 B" method=GET path=/ request_id="0776e8d9b6-691af068f4" size="0" status="0"

Stan proposed a solution , that is not yet tested :

func SetCurrentUser(next buffalo.Handler) buffalo.Handler {

here
https://github.com/gobuffalo/gothrecipe/blob/master/actions/auth.go#L66

Could be changed for:

Proposed PR by Stan:

func SetCurrentUser(next buffalo.Handler) buffalo.Handler {
    return func(c buffalo.Context) error {
        if uid := c.Session().Get("current_user_id"); uid != nil {
            u := &models.User{}
            tx := c.Value("tx").(*pop.Connection)
            if err := tx.Find(u, uid); err != nil {
                if errors.Cause(err) == sql.ErrNoRows {
                    // The session is valid, but no data matches in db
                    // Drop the session
                    c.Session().Delete("current_user_id")
                    return next(c)
                }
                // Otherwise, this is a real error...
                return errors.WithStack(err)
            }
            c.Set("current_user", u)
        }
        return next(c)
    }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant