ErlyORM / boss_db

BossDB: a sharded, caching, pooling, evented ORM for Erlang
Other
277 stars 138 forks source link

Model error #283

Closed mobilemindtec closed 3 years ago

mobilemindtec commented 3 years ago

Hi,

I'm getting the following error after updating my project. Did anything change regarding the model declaration?

OTP 21 ChicagoBoss 0.9.0

2021-11-11 17:15:15 =ERROR REPORT====
** Generic server <0.153.0> terminating 
** Last message in was {find,tenant,[{name,equals,"Mobile Mind"}],1,0,id,ascending,[]}
** When Server state == {state,connected,1,undefined,[{adapter,mysql},{cache_enable,false},{cache_prefix,db},{shards,[]},{is_master_node,true},{db_database,"emkt"},{db_password,"131054"},{db_username,"root"},{db_host,"localhost"},{db_port,3306},{name,{local,boss_db_pool}},{worker_module,boss_db_controller},{size,5},{max_overflow,10}],boss_db_adapter_mysql,<0.158.0>,<0.158.0>,[],{dict,0,16,16,8,80,48,{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}},false,60,db,0}
** Reason for termination == 
** {badarg,[{erlang,apply,[{tenant,id,undefined,undefined,undefined,undefined,undefined,undefined},database_table,[]],[]},{boss_record_lib,database_table,1,[{file,"src/boss_record_lib.erl"},{line,110}]},{boss_db_adapter_mysql,build_select_query,6,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,354}]},{boss_db_adapter_mysql,find,7,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,70}]},{boss_db_controller,handle_call,3,[{file,"src/boss_db_controller.erl"},{line,122}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,661}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,690}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}
** Client boss_web stacktrace
** [{gen,do_call,4,[{file,"gen.erl"},{line,169}]},{gen_server,call,3,[{file,"gen_server.erl"},{line,219}]},{boss_pool,call,3,[{file,"src/boss_pool.erl"},{line,12}]},{boss_db,find_first,3,[{file,"src/boss_db.erl"},{line,221}]},{bootstrap,init,0,[{file,"/emkt/src/lib/bootstrap.erl"},{line,6}]},{emkt_init,init,0,[{file,"/emkt/priv/init/emkt_init.erl"},{line,10}]},{boss_web_controller,process_compile_result,3,[{file,"src/boss/boss_web_controller.erl"},{line,202}]},{lists,foldl,3,[{file,"lists.erl"},{line,1263}]}]
2021-11-11 17:15:15 =CRASH REPORT====
  crasher:
    initial call: boss_db_controller:init/1
    pid: <0.153.0>
    registered_name: []
    exception error: bad argument: [{erlang,apply,[{tenant,id,undefined,undefined,undefined,undefined,undefined,undefined},database_table,[]],[]},{boss_record_lib,database_table,1,[{file,"src/boss_record_lib.erl"},{line,110}]},{boss_db_adapter_mysql,build_select_query,6,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,354}]},{boss_db_adapter_mysql,find,7,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,70}]},{boss_db_controller,handle_call,3,[{file,"src/boss_db_controller.erl"},{line,122}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,661}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,690}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]
    ancestors: [<0.148.0>,boss_db_pool,boss_db_sup,boss_web,boss_sup,<0.143.0>]
    message_queue_len: 0
    messages: []
    links: [<0.148.0>,<0.158.0>,<0.147.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 6772
    stack_size: 27
    reductions: 21180
  neighbours:
    neighbour: [{pid,<0.163.0>},{registered_name,[]},{initial_call,{erlang,apply,2}},{current_function,{mysql_recv,loop,1}},{ancestors,[]},{message_queue_len,0},{links,[<0.158.0>,#Port<0.10>]},{trap_exit,false},{status,waiting},{heap_size,376},{stack_size,6},{reductions,674},{current_stacktrace,[{mysql_recv,loop,1,[{file,"src/mysql_recv.erl"},{line,133}]}]}]
    neighbour: [{pid,<0.158.0>},{registered_name,[]},{initial_call,{erlang,apply,2}},{current_function,{mysql_conn,loop,1}},{ancestors,[]},{message_queue_len,0},{links,[<0.153.0>,<0.163.0>]},{trap_exit,false},{status,waiting},{heap_size,376},{stack_size,4},{reductions,518},{current_stacktrace,[{mysql_conn,loop,1,[{file,"src/mysql_conn.erl"},{line,402}]}]}]
2021-11-11 17:15:15 =SUPERVISOR REPORT====
     Supervisor: {<0.148.0>,poolboy_sup}
     Context:    child_terminated
     Reason:     {badarg,[{erlang,apply,[{tenant,id,undefined,undefined,undefined,undefined,undefined,undefined},database_table,[]],[]},{boss_record_lib,database_table,1,[{file,"src/boss_record_lib.erl"},{line,110}]},{boss_db_adapter_mysql,build_select_query,6,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,354}]},{boss_db_adapter_mysql,find,7,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,70}]},{boss_db_controller,handle_call,3,[{file,"src/boss_db_controller.erl"},{line,122}]},{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,661}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,690}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,249}]}]}
     Offender:   [{pid,<0.153.0>},{id,boss_db_controller},{mfargs,{boss_db_controller,start_link,undefined}},{restart_type,temporary},{shutdown,5000},{child_type,worker}]

My model:

tenant.erl

-module(tenant, [
    Id, 
    CreatedAt::datetime(),
    UpdatedAt::datetime(),
        Name::string(),
        Email::string(),
        Cnpj::string(),
        Enabled::boolean()
]).

-compile(export_all).

-table("tenants").

validation_tests() ->
  [{fun() -> length(Name) > 0 end,
        "Name must be non-empty!"}, 
  {fun() -> length(Email) > 0 end,
        "E-mail must be non-empty!"},
  {fun() -> length(Cnpj) > 0 end,
        "Cnpj must be non-empty!"}].

before_create() ->
  Now = calendar:local_time(),
  ModifiedRecord = set([{created_at, Now}, {updated_at, Now}]),
  {ok, ModifiedRecord}.

before_update() ->
  Now = calendar:local_time(),
  ModifiedRecord = set([{updated_at, Now}]),
  {ok, ModifiedRecord}.