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

Model.all allows passing singular values to DB::Adapter#select #365

Open
elaine-jackson opened this issue Sep 26, 2019 · 2 comments
Open

Comments

@elaine-jackson
Copy link

elaine-jackson commented Sep 26, 2019

Running amber in Crystal 0.30.1 encounters a Granite bug. Information is as follows.

Error output:

╰─$ amber watch
07:54:31 Watch run  | (INFO) Building...
Showing last frame. Use --error-trace for full trace.

In lib/granite/src/adapter/base.cr:52:12

 52 | db.query statement, args: params do |rs|
         ^----
Error: no overload matches 'DB::Database#query' with types String, args: (Int32 | Nil)

Overloads are:
 - DB::QueryMethods(Stmt)#query(query, *args_, args : Array | ::Nil = nil)
 - DB::QueryMethods(Stmt)#query(query, *args_, args : Array | ::Nil = nil, &block)
07:54:33 Watch run  | (INFO) Compile time errors detected, exiting...

My shards.yml file:

name: ulayer
version: 0.1.0

authors:
  - Nathaniel Suchy <[email protected]>

crystal: 0.30.1

license: UNLICENSED

targets:
  ulayer:
    main: src/ulayer.cr

  amber:
    main: lib/amber/src/amber/cli.cr

dependencies:
  # amber:
  #   github: amberframework/amber
  #   version: ~> 0.30.1
  amber:
    github: bcardiff/amber
    branch: crystal/0.31.0

  granite:
    github: amberframework/granite
    version: ~> 0.17.3

  quartz_mailer:
    github: amberframework/quartz-mailer
    version: ~> 0.5.3

  jasper_helpers:
    github: amberframework/jasper-helpers
    version: ~> 0.2.5

  pg:
    github: will/crystal-pg
    version: ~> 0.19.0

  mysql:
    github: crystal-lang/crystal-mysql
    version: ~> 0.9.0

  citrine-i18n:
    github: amberframework/citrine-i18n
    version: ~> 0.4.0

  crylog:
    github: Blacksmoke16/crylog

  CrystalProxmox:
    github: ulayer/CrystalProxmox

My shards.lock file

version: 1.0
shards:
  CrystalProxmox:
    github: ulayer/CrystalProxmox
    commit: 79d026f2bf579ead3974b10efaa511db8caa08fd

  amber:
    github: bcardiff/amber
    commit: d6dce70e2996e26d34ecb2099ec0c8bf6af104dc

  amber_router:
    github: amberframework/amber-router
    version: 0.3.0

  callback:
    github: drujensen/callback
    version: 0.7.1

  citrine-i18n:
    github: amberframework/citrine-i18n
    version: 0.4.0

  cli:
    github: drujensen/cli
    version: 0.8.0

  compiled_license:
    github: elorest/compiled_license
    version: 0.1.3

  crylog:
    github: Blacksmoke16/crylog
    version: 0.1.2

  db:
    github: crystal-lang/crystal-db
    version: 0.7.0

  email:
    github: arcage/crystal-email
    version: 0.3.3

  exception_page:
    github: crystal-loot/exception_page
    version: 0.1.2

  granite:
    github: amberframework/granite
    version: 0.17.3

  i18n:
    github: TechMagister/i18n.cr
    version: 0.3.1

  inflector:
    github: phoffer/inflector.cr
    version: 0.1.8

  jasper_helpers:
    github: amberframework/jasper-helpers
    version: 0.2.5

  kilt:
    github: jeromegn/kilt
    version: 0.4.0

  liquid:
    github: TechMagister/liquid.cr
    version: 0.3.1

  markd:
    github: icyleaf/markd
    version: 0.1.2

  micrate:
    github: amberframework/micrate
    version: 0.3.4

  mysql:
    github: crystal-lang/crystal-mysql
    version: 0.9.0

  optarg:
    github: drujensen/optarg
    version: 0.7.0

  pg:
    github: will/crystal-pg
    version: 0.19.0

  pool:
    github: ysbaddaden/pool
    version: 0.2.3

  quartz_mailer:
    github: amberframework/quartz-mailer
    version: 0.5.3

  redis:
    github: stefanwille/crystal-redis
    version: 2.2.1

  shell-table:
    github: luckyframework/shell-table.cr
    commit: 078a04ea58ead5203bb435a3b5fff448ddabaeea

  slang:
    github: jeromegn/slang
    version: 1.7.1

  sqlite3:
    github: crystal-lang/crystal-sqlite3
    version: 0.14.0

  string_inflection:
    github: mosop/string_inflection
    version: 0.2.1

  teeplate:
    github: mosop/teeplate
    version: 0.8.0
@elaine-jackson
Copy link
Author

@Blacksmoke16 This is a full error trace, hope it helps

crystal run src/ulayer.cr --error-trace                                                      1 ↵
In src/ulayer.cr:1:1

 1 | require "../config/application"
     ^
Error: while requiring "../config/application"


In config/application.cr:23:1

 23 | require "./routes"
      ^
Error: while requiring "./routes"


In config/routes.cr:1:15

 1 | Amber::Server.configure do
                   ^--------
Error: instantiating 'Amber::Server.class#configure()'


In config/routes.cr:1:15

 1 | Amber::Server.configure do
                   ^--------
Error: instantiating 'Amber::Server.class#configure()'


In config/routes.cr:79:3

 79 | routes :user do
      ^
Error: expanding macro


There was a problem expanding macro 'routes'

Called macro defined in lib/amber/src/amber/dsl/server.cr:2:3

 2 | macro routes(valve, scope = "")

Which expanded to:

 >  1 |     router.draw :user, "" do
 >  2 |       begin namespace("/services") do
 >  3 |   namespace("/virtual_machines") do
 >  4 |     get("/", VirtualMachineController, :list)
 >  5 |     get("/:server_id", VirtualMachineController, :display)
 >  6 |     post("/:server_id/start", VirtualMachineController, :start)
 >  7 |     post("/:server_id/shutdown", VirtualMachineController, :shutdown)
 >  8 |     post("/:server_id/halt", VirtualMachineController, :halt)
 >  9 |     post("/:server_id/reset", VirtualMachineController, :reset)
 > 10 |     post("/:server_id/suspend", VirtualMachineController, :suspend)
 > 11 |     post("/:server_id/resume", VirtualMachineController, :resume)
 > 12 |   end
 > 13 | end end
 > 14 |     end
 > 15 |   
Error: instantiating 'Amber::Router::Router#draw(Symbol, String)'


In config/routes.cr:79:3

 79 | routes :user do
      ^
Error: expanding macro


There was a problem expanding macro 'routes'

Called macro defined in lib/amber/src/amber/dsl/server.cr:2:3

 2 | macro routes(valve, scope = "")

Which expanded to:

 >  1 |     router.draw :user, "" do
 >  2 |       begin namespace("/services") do
 >  3 |   namespace("/virtual_machines") do
 >  4 |     get("/", VirtualMachineController, :list)
 >  5 |     get("/:server_id", VirtualMachineController, :display)
 >  6 |     post("/:server_id/start", VirtualMachineController, :start)
 >  7 |     post("/:server_id/shutdown", VirtualMachineController, :shutdown)
 >  8 |     post("/:server_id/halt", VirtualMachineController, :halt)
 >  9 |     post("/:server_id/reset", VirtualMachineController, :reset)
 > 10 |     post("/:server_id/suspend", VirtualMachineController, :suspend)
 > 11 |     post("/:server_id/resume", VirtualMachineController, :resume)
 > 12 |   end
 > 13 | end end
 > 14 |     end
 > 15 |   
Error: instantiating 'Amber::Router::Router#draw(Symbol, String)'


There was a problem expanding macro 'get'

Called macro defined in macro 'macro_4597521920'

 2 | macro get(*args)

Which expanded to:

 > 1 |         route :get, "/", VirtualMachineController, :list
 > 2 |         
 > 3 |         route :head, "/", VirtualMachineController, :list
 > 4 |         
 > 5 |         
 > 6 |         route :options, "/", VirtualMachineController, :list
 > 7 |         
 > 8 |       
Error: expanding macro


There was a problem expanding macro 'route'

Called macro defined in lib/amber/src/amber/dsl/router.cr:11:5

 11 | macro route(verb, resource, controller, action, constraints = {} of String => Regex)

Which expanded to:

 >  1 |       __temp_2287 = ->(context : HTTP::Server::Context){
 >  2 |         controller = VirtualMachineController.new(context)
 >  3 |         controller.run_before_filter(:list) unless context.content
 >  4 |         unless context.content
 >  5 |           context.content = controller.list.to_s
 >  6 |           controller.run_after_filter(:list)
 >  7 |         end
 >  8 |       }
 >  9 |       __temp_2288 = "GET"
 > 10 |       __temp_2289 = Amber::Route.new(
 > 11 |         __temp_2288, "/", __temp_2287, :list, valve, scope, "VirtualMachineController", {} of String => Regex
 > 12 |       )
 > 13 | 
 > 14 |       router.add(__temp_2289)
 > 15 |     
Error: instantiating 'VirtualMachineController#list()'


In src/controllers/virtual_machine_controller.cr:6:57

 6 | return render("./error.ecr") unless (servers = user.servers)
                                                         ^------
Error: instantiating 'BlestaUser#servers()'


In src/models/blesta_user.cr:31:33

 31 | shared_vms = VirtualMachine.all("WHERE ? = ANY(allowed_clients)", client.id_value)
                                  ^--
Error: instantiating 'VirtualMachine.class#all(String, (Int32 | Nil))'


In lib/granite/src/granite/querying.cr:32:30

 32 | Collection(self).new(->{ raw_all(clause, params) })
                               ^------
Error: instantiating 'raw_all(String, (Int32 | Nil))'


In lib/granite/src/granite/querying.cr:15:13

 15 | adapter.select(select_container, clause, params) do |results|
              ^-----
Error: instantiating 'Granite::Adapter::Base+#select(Granite::Select::Container, String, (Int32 | Nil))'


In lib/granite/src/adapter/base.cr:50:25

 50 | elapsed_time = Time.measure do
                          ^------
Error: instantiating 'Time.class#measure()'


In lib/granite/src/adapter/base.cr:50:25

 50 | elapsed_time = Time.measure do
                          ^------
Error: instantiating 'Time.class#measure()'


In lib/granite/src/adapter/base.cr:51:7

 51 | open do |db|
      ^---
Error: instantiating 'open()'


In lib/granite/src/adapter/base.cr:51:7

 51 | open do |db|
      ^---
Error: instantiating 'open()'


In lib/granite/src/adapter/base.cr:52:12

 52 | db.query statement, args: params do |rs|
         ^----
Error: no overload matches 'DB::Database#query' with types String, args: (Int32 | Nil)

Overloads are:
 - DB::QueryMethods(Stmt)#query(query, *args_, args : Array | ::Nil = nil)
 - DB::QueryMethods(Stmt)#query(query, *args_, args : Array | ::Nil = nil, &block)
╭─nathanielsuchy@Nathaniels-MacBook-Pro ~/Code/ulayer ‹master*› 
╰─$                                                                                              1 ↵

@Blacksmoke16
Copy link
Contributor

Blacksmoke16 commented Sep 27, 2019

This is due to the upgrade to [email protected], specifically it seems Model.all("WHERE", user_id) where this gets passed to the select query that is expecting an array.

@Blacksmoke16 Blacksmoke16 changed the title Running Amber Watch triggers a Granite bug Model.all allows passing singular values to DB::Adapter#select Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants