leafo / lapis

A web framework for Lua and OpenResty written in MoonScript
http://leafo.net/lapis/
MIT License
3.14k stars 247 forks source link

Validations break when lua code cache is enabled #748

Closed semyon422 closed 2 years ago

semyon422 commented 2 years ago

Here: https://github.com/leafo/lapis/blob/9208d1c440a23398efc32f9dd09c6a80f836313c/lapis/validate.lua#L94 If i have validation {"some_flag", type = "boolean", optional = true} and I validate it at least one time with some_flag that "exists" it becomes {"some_flag", type = "boolean"}.

semyon422 commented 2 years ago

Working solution for me is deleting this line and adding validate.validate_functions.optional = function(input) return true, "" end

leafo commented 2 years ago

Good catch, fix is pushed and I'll try to get out a new version shortly.

You can work around the issue by ensuring that you create a new validations object for every call to validate (most likely on every request)