alexedwards / scs

HTTP Session Management for Go
MIT License
2.02k stars 165 forks source link

Sqlite3store error constraint failed: NOT NULL constraint failed: sessions.expiry (1299) #170

Closed LordPraslea closed 8 months ago

LordPraslea commented 1 year ago

Hi

While trying to explore this module I came across an error and thus the sessions are not saved properly when using sqlite3store. I'm using Go v1.20.1 2023/07/05 14:48:30 constraint failed: NOT NULL constraint failed: sessions.expiry (1299)

Removing the NOT NULL constraint from the expiry does save the data, but without an expiry date. What I can think of is that when expiry is getting sent to juliandate with a date such as "2023-07-06 11:48:30.497057128 +0000 UTC 60611+00-23 77:118:09" it returns null.

A simple solution would be to simply pass a simpler format such as 2023-07-06 11:48:30
Line 54

expiry.Format("2006-01-02T15:04:05")

OR change the row and logic to use DATETIME

It does seem to work with the in memory version

Let me know if I should do a pull request.

Jinnrry commented 11 months ago

I get same error also. My sqlite driver is modernc.org/sqlite.

Jinnrry commented 11 months ago

https://github.com/alexedwards/scs/blob/master/sqlite3store/sqlite3store.go#L51

Format the expiry , it will work.

alexedwards commented 8 months ago

@LordPraslea I've tried to replicate this problem and I can't --- following the setup instructions in the README (https://github.com/alexedwards/scs/tree/master/sqlite3store) and using the example code, the expiry date seems to be set with no problems.

Could you provide some example code that demonstrates the issue?

alexedwards commented 8 months ago

@LordPraslea Actually don't worry about the example. Looking through the SQLite docs I can see that julianday potentially doesn't work with all values returned by time.Time.String() and that's enough to go on.

I've pushed commit https://github.com/alexedwards/scs/commit/84bd122bd881c23458294d70a04e0ba6974fe2cd which should fix this --- it now converts the expiry to UTC and formats it to "2006-01-02T15:04:05.999" before doing the insert.

I'm going to close this, but please reopen if there continues to be a problem.