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

Unable to have nullable array column #38

Closed
Blacksmoke16 opened this issue Sep 5, 2018 · 4 comments
Closed

Unable to have nullable array column #38

Blacksmoke16 opened this issue Sep 5, 2018 · 4 comments
Labels
Milestone

Comments

@Blacksmoke16
Copy link
Contributor

model

class Test
  include Clear::Model
  self.table = "test"

  with_serial_pkey
  column names : Array(String)?
end
Error in src/mosquito.cr:17: expanding macro

  column names : Array(String)?
  ^~~~~~

in lib/clear/src/clear/model/modules/has_columns.cr:93: undefined macro method 'Generic#resolve'

            converter = ("Clear::Model::Converter::" + _type.types.map(&.resolve).map(&.stringify).sort.reject { |x| x == "Nil" }.join("") + "Converter").id
                                                                   ^~~

in lib/clear/src/clear/model/modules/has_columns.cr:93: undefined macro method 'Generic#resolve'

            converter = ("Clear::Model::Converter::" + _type.types.map(&.resolve).map(&.stringify).sort.reject { |x| x == "Nil" }.join("") + "Converter").id
                                                                         ^~~~~~~

in src/mosquito.cr:17: undefined macro method 'Generic#resolve'

  column names : Array(String)?
                 ^

I also tested with Array(Int64)? and Array(Int32)? and same error

@Blacksmoke16
Copy link
Contributor Author

Blacksmoke16 commented Sep 5, 2018

On a similar note, it is also not possible to insert an empty array.

class Test
  include Clear::Model
  self.table = "test"

  with_serial_pkey
  column names : Array(String)
end

Test.create({names: [] of String})
2018-09-05 22:36:26.773 UTC [782] ERROR:  cannot determine type of empty array at character 472
2018-09-05 22:36:26.773 UTC [782] HINT:  Explicitly cast to the desired type, for example ARRAY[]::integer[].
2018-09-05 22:36:26.773 UTC [782] STATEMENT:  INSERT INTO "test" ("names") VALUES (Array[]) RETURNING *
Error catched, last request was:
INSERT INTO "test" ("names") VALUES (Array[]) RETURNING *
I, [2018-09-05 22:36:26 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] Job failed! Raised PQ::PQError: cannot determine type of empty array
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pq/connection.cr:198:7 in 'handle_error'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pq/connection.cr:0:9 in 'handle_async_frames'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pq/connection.cr:157:7 in 'read'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pq/connection.cr:152:7 in 'read'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pq/connection.cr:295:31 in 'expect_frame'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pq/connection.cr:294:5 in 'expect_frame'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/pg/src/pg/statement.cr:18:5 in 'perform_query'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/db/src/db/statement.cr:103:14 in 'perform_query_with_rescue'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/db/src/db/statement.cr:83:7 in 'query'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/db/src/db/pool_statement.cr:29:30 in 'query'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/db/src/db/query_methods.cr:38:7 in 'query'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/clear/src/clear/sql/insert_query.cr:53:12 in 'execute'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/clear/src/clear/model/modules/has_saving.cr:29:22 in 'save'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/clear/src/clear/model/modules/has_saving.cr:53:67 in 'save!'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] src/EveToolsApi/tasks/scheduled/update_couriers.cr:30:11 in 'perform'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/mosquito/src/mosquito/job.cr:35:7 in 'run'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/mosquito/src/mosquito/task.cr:73:10 in 'run'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/mosquito/src/mosquito/runner.cr:122:14 in 'run_next_task'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/mosquito/src/mosquito/runner.cr:86:9 in 'dequeue_and_run_tasks'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/mosquito/src/mosquito/runner.cr:30:9 in 'run'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] lib/mosquito/src/mosquito/runner.cr:10:7 in 'start'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] src/EveToolsApi/tasks/scripts/load_systems.cr:26:5 in '__crystal_main'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] /usr/share/crystal/src/crystal/main.cr:97:5 in 'main_user_code'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] /usr/share/crystal/src/crystal/main.cr:86:7 in 'main'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] /usr/share/crystal/src/crystal/main.cr:106:3 in 'main'
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] __libc_start_main
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] _start
I, [2018-09-05 22:36:27 +00:00 #2679]  INFO -- : [EveToolsApi::Tasks::UpdateCouriers-mosquito:task:1536186985258:771] ???

@anykeyh
Copy link
Owner

anykeyh commented Sep 11, 2018

The second bug is fixed on local on my machine, but the first one is a difficult one. The converter macro system has some limits, and I need to rewrite completely the system. However, there's an issue with macro and generic, and I've raised an issue in crystal.

For now I won't fix until I get more information from the crystal team.

@anykeyh
Copy link
Owner

anykeyh commented Sep 11, 2018

For now, you can manually add a converter on your column:

column names : Array(String)?, converter: Clear::Model::Converter::ArrayConverter_String_

It should fix temporarly the bug!

@anykeyh
Copy link
Owner

anykeyh commented Oct 31, 2018

Related to #43

The problem with Generic#resolve has been fixed in Crystal 0.27, which is going to get released really soon 🎉 🍾

I will spend few days working on Clear soon to close this issue and improve the library ! 😄

@anykeyh anykeyh added this to the 0.4 milestone Oct 31, 2018
anykeyh added a commit that referenced this issue Nov 8, 2018
anykeyh added a commit that referenced this issue Nov 8, 2018
* Change converter design. Manual to write. Fix #38, #43, #46 
* Add support for `ON CONFLICT DO UPDATE / DO NOTHING`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants