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

The list generates incorrect SQL query for a Materialised View's Model #2959

Open
pranjalnanavaty opened this issue Nov 22, 2017 · 1 comment

Comments

@pranjalnanavaty
Copy link

I have created a materialised view named awards_reports on table named awards.

In rails_admin I have added a model for AwardsReport. Now when I try to click on Awards reports in the navigation the following error comes up:

AwardsReport Load (1.1ms) SELECT "awards_reports".* FROM "awards_reports" ORDER BY awards_reports. desc LIMIT $1 OFFSET $2 [["LIMIT", 20], ["OFFSET", 0]]
Rendered /usr/local/lib/ruby/gems/2.3.0/gems/rails_admin-1.2.0/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/application (40.9ms)
Completed 500 Internal Server Error in 782ms (ActiveRecord: 11.3ms)

ActionView::Template::Error (PG::UndefinedColumn: ERROR: column awards_reports.desc does not exist
LINE 1: ..."awards_reports".* FROM "awards_reports" ORDER BY awards_rep...
^
: SELECT "awards_reports".* FROM "awards_reports" ORDER BY awards_reports. desc LIMIT $1 OFFSET $2):
89: %th.other.right.shrink= "..."
90: %th.last.shrink
91: %tbody
92: - @objects.each do |object|
93: %tr{class: "#{@abstract_model.param_key}_row #{@model_config.list.with(object: object).row_css_class}"}
94: %td
95: = check_box_tag "bulk_ids[]", object.id, false

activerecord (5.0.6) lib/active_record/connection_adapters/postgresql_adapter.rb:598:in async_exec' activerecord (5.0.6) lib/active_record/connection_adapters/postgresql_adapter.rb:598:in block in exec_no_cache'
activerecord (5.0.6) lib/active_record/connection_adapters/abstract_adapter.rb:590:in block in log' activesupport (5.0.6) lib/active_support/notifications/instrumenter.rb:21:in instrument'
activerecord (5.0.6) lib/active_record/connection_adapters/abstract_adapter.rb:583:in log' activerecord (5.0.6) lib/active_record/connection_adapters/postgresql_adapter.rb:598:in exec_no_cache'
activerecord (5.0.6) lib/active_record/connection_adapters/postgresql_adapter.rb:587:in execute_and_clear' activerecord (5.0.6) lib/active_record/connection_adapters/postgresql/database_statements.rb:103:in exec_query'
activerecord (5.0.6) lib/active_record/connection_adapters/abstract/database_statements.rb:373:in select' activerecord (5.0.6) lib/active_record/connection_adapters/abstract/database_statements.rb:41:in select_all'
activerecord (5.0.6) lib/active_record/connection_adapters/abstract/query_cache.rb:93:in block in select_all' activerecord (5.0.6) lib/active_record/connection_adapters/abstract/query_cache.rb:108:in cache_sql'
activerecord (5.0.6) lib/active_record/connection_adapters/abstract/query_cache.rb:93:in select_all' activerecord (5.0.6) lib/active_record/querying.rb:39:in find_by_sql'
activerecord (5.0.6) lib/active_record/relation.rb:706:in exec_queries' activerecord (5.0.6) lib/active_record/relation.rb:583:in load'
activerecord (5.0.6) lib/active_record/relation.rb:260:in records' activerecord (5.0.6) lib/active_record/relation/delegation.rb:38:in each'
rails_admin (1.2.0) app/views/rails_admin/main/index.html.haml:92:in block in __usr_local_lib_ruby_gems_______gems_rails_admin_______app_views_rails_admin_main_index_html_haml__4038848536059001495_47135327687180' haml (5.0.3) lib/haml/helpers/action_view_mods.rb:115:in block (2 levels) in form_tag_with_haml'
haml (5.0.3) lib/haml/helpers.rb:292:in with_tabs' haml (5.0.3) lib/haml/helpers/action_view_mods.rb:115:in block in form_tag_with_haml'
haml (5.0.3) lib/haml/helpers.rb:690:in block in haml_bind_proc' haml (5.0.3) lib/haml/helpers.rb:382:in block in capture_haml'
haml (5.0.3) lib/haml/helpers.rb:667:in with_haml_buffer' haml (5.0.3) lib/haml/helpers.rb:378:in capture_haml'
haml (5.0.3) lib/haml/helpers/xss_mods.rb:62:in capture_haml_with_haml_xss' haml (5.0.3) lib/haml/helpers/action_view_mods.rb:45:in capture_with_haml'
actionview (5.0.6) lib/action_view/helpers/form_tag_helper.rb:70:in form_tag' haml (5.0.3) lib/haml/helpers/action_view_mods.rb:118:in form_tag_with_haml'
haml (5.0.3) lib/haml/helpers/action_view_xss_mods.rb:19:in form_tag_with_haml_xss' rails_admin (1.2.0) app/views/rails_admin/main/index.html.haml:69:in __usr_local_lib_ruby_gems_______gems_rails_admin_______app_views_rails_admin_main_index_html_haml__4038848536059001495_47135327687180'
actionview (5.0.6) lib/action_view/template.rb:159:in block in render' activesupport (5.0.6) lib/active_support/notifications.rb:166:in instrument'
actionview (5.0.6) lib/action_view/template.rb:354:in instrument' actionview (5.0.6) lib/action_view/template.rb:157:in render'
actionview (5.0.6) lib/action_view/renderer/template_renderer.rb:54:in block (2 levels) in render_template' actionview (5.0.6) lib/action_view/renderer/abstract_renderer.rb:42:in block in instrument'
activesupport (5.0.6) lib/active_support/notifications.rb:164:in block in instrument' activesupport (5.0.6) lib/active_support/notifications/instrumenter.rb:21:in instrument'
activesupport (5.0.6) lib/active_support/notifications.rb:164:in instrument' actionview (5.0.6) lib/action_view/renderer/abstract_renderer.rb:41:in instrument'
actionview (5.0.6) lib/action_view/renderer/template_renderer.rb:53:in block in render_template' actionview (5.0.6) lib/action_view/renderer/template_renderer.rb:61:in render_with_layout'
actionview (5.0.6) lib/action_view/renderer/template_renderer.rb:52:in render_template' actionview (5.0.6) lib/action_view/renderer/template_renderer.rb:14:in render'
actionview (5.0.6) lib/action_view/renderer/renderer.rb:42:in render_template' actionview (5.0.6) lib/action_view/renderer/renderer.rb:23:in render'
actionview (5.0.6) lib/action_view/rendering.rb:104:in _render_template' actionpack (5.0.6) lib/action_controller/metal/streaming.rb:217:in _render_template'
actionview (5.0.6) lib/action_view/rendering.rb:83:in render_to_body' actionpack (5.0.6) lib/action_controller/metal/rendering.rb:52:in render_to_body'
actionpack (5.0.6) lib/action_controller/metal/renderers.rb:142:in render_to_body' actionpack (5.0.6) lib/abstract_controller/rendering.rb:26:in render'
actionpack (5.0.6) lib/action_controller/metal/rendering.rb:36:in render' actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:44:in block (2 levels) in render'
activesupport (5.0.6) lib/active_support/core_ext/benchmark.rb:12:in block in ms' /usr/local/lib/ruby/2.3.0/benchmark.rb:308:in realtime'
activesupport (5.0.6) lib/active_support/core_ext/benchmark.rb:12:in ms' actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:44:in block in render'
actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:87:in cleanup_view_runtime' activerecord (5.0.6) lib/active_record/railties/controller_runtime.rb:25:in cleanup_view_runtime'
actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:43:in render' remotipart (1.3.1) lib/remotipart/render_overrides.rb:16:in render_with_remotipart'
rails_admin (1.2.0) lib/rails_admin/config/actions/index.rb:44:in block (4 levels) in <class:Index>' actionpack (5.0.6) lib/action_controller/metal/mime_responds.rb:201:in respond_to'
rails_admin (1.2.0) lib/rails_admin/config/actions/index.rb:42:in block (2 levels) in <class:Index>' rails_admin (1.2.0) app/controllers/rails_admin/main_controller.rb:22:in instance_eval'
rails_admin (1.2.0) app/controllers/rails_admin/main_controller.rb:22:in index' actionpack (5.0.6) lib/action_controller/metal/basic_implicit_render.rb:4:in send_action'
actionpack (5.0.6) lib/abstract_controller/base.rb:188:in process_action' actionpack (5.0.6) lib/action_controller/metal/rendering.rb:30:in process_action'
actionpack (5.0.6) lib/abstract_controller/callbacks.rb:20:in block in process_action' activesupport (5.0.6) lib/active_support/callbacks.rb:126:in call'
activesupport (5.0.6) lib/active_support/callbacks.rb:506:in block (2 levels) in compile' activesupport (5.0.6) lib/active_support/callbacks.rb:455:in call'
activesupport (5.0.6) lib/active_support/callbacks.rb:101:in __run_callbacks__' activesupport (5.0.6) lib/active_support/callbacks.rb:750:in _run_process_action_callbacks'
activesupport (5.0.6) lib/active_support/callbacks.rb:90:in run_callbacks' actionpack (5.0.6) lib/abstract_controller/callbacks.rb:19:in process_action'
actionpack (5.0.6) lib/action_controller/metal/rescue.rb:20:in process_action' actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:32:in block in process_action'
activesupport (5.0.6) lib/active_support/notifications.rb:164:in block in instrument' activesupport (5.0.6) lib/active_support/notifications/instrumenter.rb:21:in instrument'
activesupport (5.0.6) lib/active_support/notifications.rb:164:in instrument' actionpack (5.0.6) lib/action_controller/metal/instrumentation.rb:30:in process_action'
actionpack (5.0.6) lib/action_controller/metal/params_wrapper.rb:248:in process_action' activerecord (5.0.6) lib/active_record/railties/controller_runtime.rb:18:in process_action'
actionpack (5.0.6) lib/abstract_controller/base.rb:126:in process' actionview (5.0.6) lib/action_view/rendering.rb:30:in process'
actionpack (5.0.6) lib/action_controller/metal.rb:190:in dispatch' actionpack (5.0.6) lib/action_controller/metal.rb:262:in dispatch'
actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:50:in dispatch' actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:32:in serve'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:39:in block in serve' actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in each'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in serve' actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:727:in call'
railties (5.0.6) lib/rails/engine.rb:522:in call' railties (5.0.6) lib/rails/railtie.rb:193:in public_send'
railties (5.0.6) lib/rails/railtie.rb:193:in method_missing' actionpack (5.0.6) lib/action_dispatch/routing/mapper.rb:17:in block in class:Constraints'
actionpack (5.0.6) lib/action_dispatch/routing/mapper.rb:46:in serve' actionpack (5.0.6) lib/action_dispatch/journey/router.rb:39:in block in serve'
actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in each' actionpack (5.0.6) lib/action_dispatch/journey/router.rb:26:in serve'
actionpack (5.0.6) lib/action_dispatch/routing/route_set.rb:727:in call' rack-pjax (1.0.0) lib/rack/pjax.rb:12:in call'
remotipart (1.3.1) lib/remotipart/middleware.rb:32:in call' warden (1.2.6) lib/warden/manager.rb:35:in block in call'
warden (1.2.6) lib/warden/manager.rb:34:in catch' warden (1.2.6) lib/warden/manager.rb:34:in call'
rack (2.0.3) lib/rack/etag.rb:25:in call' rack (2.0.3) lib/rack/conditional_get.rb:25:in call'
rack (2.0.3) lib/rack/head.rb:12:in call' rack (2.0.3) lib/rack/session/abstract/id.rb:232:in context'
rack (2.0.3) lib/rack/session/abstract/id.rb:226:in call' actionpack (5.0.6) lib/action_dispatch/middleware/cookies.rb:613:in call'
activerecord (5.0.6) lib/active_record/migration.rb:553:in call' actionpack (5.0.6) lib/action_dispatch/middleware/callbacks.rb:38:in block in call'
activesupport (5.0.6) lib/active_support/callbacks.rb:97:in __run_callbacks__' activesupport (5.0.6) lib/active_support/callbacks.rb:750:in _run_call_callbacks'
activesupport (5.0.6) lib/active_support/callbacks.rb:90:in run_callbacks' actionpack (5.0.6) lib/action_dispatch/middleware/callbacks.rb:36:in call'
actionpack (5.0.6) lib/action_dispatch/middleware/executor.rb:12:in call' actionpack (5.0.6) lib/action_dispatch/middleware/remote_ip.rb:79:in call'
actionpack (5.0.6) lib/action_dispatch/middleware/debug_exceptions.rb:49:in call' web-console (3.5.1) lib/web_console/middleware.rb:135:in call_app'
web-console (3.5.1) lib/web_console/middleware.rb:20:in block in call' web-console (3.5.1) lib/web_console/middleware.rb:18:in catch'
web-console (3.5.1) lib/web_console/middleware.rb:18:in call' actionpack (5.0.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in call'
railties (5.0.6) lib/rails/rack/logger.rb:36:in call_app' railties (5.0.6) lib/rails/rack/logger.rb:24:in block in call'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:69:in block in tagged' activesupport (5.0.6) lib/active_support/tagged_logging.rb:26:in tagged'
activesupport (5.0.6) lib/active_support/tagged_logging.rb:69:in tagged' railties (5.0.6) lib/rails/rack/logger.rb:24:in call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in call' actionpack (5.0.6) lib/action_dispatch/middleware/request_id.rb:24:in call'
rack (2.0.3) lib/rack/method_override.rb:22:in call' rack (2.0.3) lib/rack/runtime.rb:22:in call'
activesupport (5.0.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in call' actionpack (5.0.6) lib/action_dispatch/middleware/executor.rb:12:in call'
actionpack (5.0.6) lib/action_dispatch/middleware/static.rb:136:in call' rack (2.0.3) lib/rack/sendfile.rb:111:in call'
railties (5.0.6) lib/rails/engine.rb:522:in call' rack (2.0.3) lib/rack/urlmap.rb:68:in block in call'
rack (2.0.3) lib/rack/urlmap.rb:53:in each' rack (2.0.3) lib/rack/urlmap.rb:53:in call'
puma (3.10.0) lib/puma/configuration.rb:225:in call' puma (3.10.0) lib/puma/server.rb:605:in handle_request'
puma (3.10.0) lib/puma/server.rb:437:in process_client' puma (3.10.0) lib/puma/server.rb:301:in block in run'
puma (3.10.0) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
Rendering /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout
Rendering /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
Rendered /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (6.9ms)
Rendering /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
Rendered /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.3ms)
Rendering /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
Rendered /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms)
Rendered /usr/local/lib/ruby/gems/2.3.0/gems/actionpack-5.0.6/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (26.1ms)

rails_admin is generating SELECT "awards_reports".* FROM "awards_reports" ORDER BY awards_reports. desc LIMIT $1 OFFSET $2 [["LIMIT", 20], ["OFFSET", 0]] query.

Instead if the query was SELECT "awards_reports".* FROM "awards_reports" ORDER BY awards_reports.id desc LIMIT $1 OFFSET $2 [["LIMIT", 20], ["OFFSET", 0]] the problem would not have occurred.

@winescout
Copy link

This happens when exporting as well. In my case, index is fine, but no submitting an export.

Mysql2::Error: Unknown column 'view_table.' in 'order clause': SELECT view_table.* FROM view_table ORDER BY view_table.`` ASC LIMIT 1000

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

2 participants