Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nested extra_fields in combination with shape #17

Open
Conni2461 opened this issue Jul 13, 2023 · 0 comments
Open

nested extra_fields in combination with shape #17

Conni2461 opened this issue Jul 13, 2023 · 0 comments

Comments

@Conni2461
Copy link

Conni2461 commented Jul 13, 2023

this is like a really weird issue and i am sorry for even opening it but i kinda have a question. I somewhat know lua/luajit because i am a maintainer of a somewhat popular project, so a coworker asked me if i could look into a lua bug that he had with another open source software, rspamd.

That software uses tableshape, so i looked into that rspamd bug (rspamd/rspamd#4318 (comment)) and after that into tableshape documentation + source code and i think i found a missuse of tableshape in rspamd. I know that is not your issue but i kinda wanna make sure that its actually a missuse.

So i've created a minimal reproduce of the code that is being executed in rspamd.

package.path = package.path .. ";./?.lua;"
local ts = require("contrib.lua-tableshape.tableshape").types

local lua_redis_common = ts.shape {
  password = ts.string:is_optional(),
}

local lua_redis =
  -- Allow separate read/write servers to allow usage in the `extra_fields`
  ts.shape({
    read_servers = ts.string + ts.array_of(ts.string),
  }, { extra_fields = lua_redis_common }) + ts.shape({
    write_servers = ts.string + ts.array_of(ts.string),
  }, { extra_fields = lua_redis_common }) + ts.shape({
    read_servers = ts.string + ts.array_of(ts.string),
    write_servers = ts.string + ts.array_of(ts.string),
  }, { extra_fields = lua_redis_common })

local settings_schema = ts.shape({
  key_prefix = ts.string,
  nrows = ts.number,
  compress = ts.boolean,
}, { extra_fields = lua_redis })

local obj1 = {
  key_prefix = "rs_history",
  nrows = 1000,
  compress = true,

  read_servers = "127.0.0.1:6381",
  write_servers = "127.0.0.1:6381",
  -- password = "<password hidden>",
}

local res, err = settings_schema:transform(obj1)
print(res, err)

as soon as i comment in password everything "explodes" with the following error

nil     field "password": expected { "read_servers" = type "string", or array of type "string" }, { "write_servers" = type "string", or array of type "string" }, { "write_servers" = type "string", or array of type "string", "read_servers
" = type "string", or array of type "string" }, { "servers" = type "string", or array of type "string" }, or { "server" = type "string", or array of type "string" }

But it should be possible to optionally add password to that table.

If you confirm that this is a usecase that is currently not supported and never will be i could just rewrite the code in rspamd 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant