Getting error when trying to sort in a Data Model

[b3faa775-cb49-4385-b7f5-25d671ec0ca6] 2022-04-20T13:16:41+03:00 DEBUG metabase.server.middleware.log POST /api/dataset 400 896.0 µs (0 DB calls)
{:via
[{:type clojure.lang.ExceptionInfo,
:message "database is required for all queries whose type is not internal.",
:data
{:status-code 400,
:query
{:type "query",
:database nil,
:query {:source-table "card__127", :order-by [["desc" ["field" 1591 nil]]]},
:parameters [],
:middleware {:js-int-to-string? true}}},
:at [metabase.api.dataset$run_query_async invokeStatic "dataset.clj" 50]}],
:trace
[[metabase.api.dataset$run_query_async invokeStatic "dataset.clj" 50]
[metabase.api.dataset$run_query_async doInvoke "dataset.clj" 41]
[clojure.lang.RestFn invoke "RestFn.java" 410]
[metabase.api.dataset$fn__65331 invokeStatic "dataset.clj" 75]
[metabase.api.dataset$fn__65331 invoke "dataset.clj" 71]
[compojure.core$wrap_response$fn__32284 invoke "core.clj" 160]
[compojure.core$wrap_route_middleware$fn__32268 invoke "core.clj" 132]
[compojure.core$wrap_route_info$fn__32273 invoke "core.clj" 139]
[compojure.core$wrap_route_matches$fn__32277 invoke "core.clj" 151]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$wrap_route_matches$fn__32277 invoke "core.clj" 152]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296 invoke "core.clj" 200]
[metabase.server.middleware.auth$enforce_authentication$fn__65391 invoke "auth.clj" 14]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296 invoke "core.clj" 200]
[compojure.core$make_context$handler__32324 invoke "core.clj" 289]
[compojure.core$make_context$fn__32328 invoke "core.clj" 299]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$make_context$fn__32328 invoke "core.clj" 300]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[metabase.api.routes$fn__76516$fn__76519 invoke "routes.clj" 56]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296 invoke "core.clj" 200]
[clojure.lang.AFn applyToHelper "AFn.java" 160]
[clojure.lang.AFn applyTo "AFn.java" 144]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.core$apply invoke "core.clj" 662]
[metabase.server.routes$fn__76661$fn__76662 doInvoke "routes.clj" 57]
[clojure.lang.RestFn invoke "RestFn.java" 436]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296 invoke "core.clj" 200]
[compojure.core$make_context$handler__32324 invoke "core.clj" 289]
[compojure.core$make_context$fn__32328 invoke "core.clj" 299]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$wrap_route_matches$fn__32277 invoke "core.clj" 153]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$wrap_route_matches$fn__32277 invoke "core.clj" 153]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[compojure.core$wrap_route_matches$fn__32277 invoke "core.clj" 153]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296$f__32297$respond_SINGLEQUOTE___32298 invoke "core.clj" 197]
[metabase.server.routes$fn__76649$fn__76651 invoke "routes.clj" 41]
[compojure.core$routes$fn__32296$f__32297 invoke "core.clj" 198]
[compojure.core$routes$fn__32296 invoke "core.clj" 200]
[metabase.server.middleware.exceptions$catch_uncaught_exceptions$fn__73644 invoke "exceptions.clj" 98]
[metabase.server.middleware.exceptions$catch_api_exceptions$fn__73641 invoke "exceptions.clj" 86]
[metabase.server.middleware.log$log_api_call$fn__77130$fn__77131$fn__77132 invoke "log.clj" 209]
[metabase.driver.sql_jdbc.execute.diagnostic$do_with_diagnostic_info invokeStatic "diagnostic.clj" 15]
[metabase.driver.sql_jdbc.execute.diagnostic$do_with_diagnostic_info invoke "diagnostic.clj" 9]
[metabase.server.middleware.log$log_api_call$fn__77130$fn__77131 invoke "log.clj" 201]
[toucan.db$_do_with_call_counting invokeStatic "db.clj" 216]
[toucan.db$_do_with_call_counting invoke "db.clj" 209]
[metabase.server.middleware.log$log_api_call$fn__77130 invoke "log.clj" 200]
[metabase.server.middleware.browser_cookie$ensure_browser_id_cookie$fn__80483 invoke "browser_cookie.clj" 38]
[metabase.server.middleware.security$add_security_headers$fn__55251 invoke "security.clj" 148]
[metabase.server.middleware.json$wrap_json_body$fn__79638 invoke "json.clj" 62]
[metabase.server.middleware.json$wrap_streamed_json_response$fn__79656 invoke "json.clj" 98]
[metabase.server.middleware.offset_paging$handle_paging$fn__55275 invoke "offset_paging.clj" 42]
[ring.middleware.keyword_params$wrap_keyword_params$fn__80750 invoke "keyword_params.clj" 55]
[ring.middleware.params$wrap_params$fn__80766 invoke "params.clj" 69]
[metabase.server.middleware.misc$maybe_set_site_url$fn__34391 invoke "misc.clj" 59]
[metabase.server.middleware.session$bind_current_user$fn__45744$fn__45745 invoke "session.clj" 262]
[metabase.server.middleware.session$do_with_current_user invokeStatic "session.clj" 243]
[metabase.server.middleware.session$do_with_current_user invoke "session.clj" 235]
[metabase.server.middleware.session$bind_current_user$fn__45744 invoke "session.clj" 261]
[metabase.server.middleware.session$wrap_current_user_info$fn__45731 invoke "session.clj" 221]
[metabase.server.middleware.session$wrap_session_id$fn__45717 invoke "session.clj" 167]
[metabase.server.middleware.auth$wrap_api_key$fn__65399 invoke "auth.clj" 27]
[ring.middleware.cookies$wrap_cookies$fn__80670 invoke "cookies.clj" 216]
[metabase.server.middleware.misc$add_content_type$fn__34374 invoke "misc.clj" 27]
[metabase.server.middleware.misc$disable_streaming_buffering$fn__34399 invoke "misc.clj" 76]
[ring.middleware.gzip$wrap_gzip$fn__80712 invoke "gzip.clj" 86]
[metabase.server.middleware.misc$bind_request$fn__34402 invoke "misc.clj" 93]
[metabase.server.middleware.ssl$redirect_to_https_middleware$fn__80499 invoke "ssl.clj" 48]
[metabase.server$async_proxy_handler$fn__76903 invoke "server.clj" 73]
[metabase.server.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a handle nil -1]
[org.eclipse.jetty.server.handler.HandlerWrapper handle "HandlerWrapper.java" 127]
[org.eclipse.jetty.server.Server handle "Server.java" 516]
[org.eclipse.jetty.server.HttpChannel lambda$handle$1 "HttpChannel.java" 388]
[org.eclipse.jetty.server.HttpChannel dispatch "HttpChannel.java" 633]
[org.eclipse.jetty.server.HttpChannel handle "HttpChannel.java" 380]
[org.eclipse.jetty.server.HttpConnection onFillable "HttpConnection.java" 277]
[org.eclipse.jetty.io.AbstractConnection$ReadCallback succeeded "AbstractConnection.java" 311]
[org.eclipse.jetty.io.FillInterest fillable "FillInterest.java" 105]
[org.eclipse.jetty.io.ChannelEndPoint$1 run "ChannelEndPoint.java" 104]
[org.eclipse.jetty.util.thread.strategy.EatWhatYouKill runTask "EatWhatYouKill.java" 338]
[org.eclipse.jetty.util.thread.strategy.EatWhatYouKill doProduce "EatWhatYouKill.java" 315]
[org.eclipse.jetty.util.thread.strategy.EatWhatYouKill tryProduce "EatWhatYouKill.java" 173]
[org.eclipse.jetty.util.thread.strategy.EatWhatYouKill run "EatWhatYouKill.java" 131]
[org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread run "ReservedThreadExecutor.java" 386]
[org.eclipse.jetty.util.thread.QueuedThreadPool runJob "QueuedThreadPool.java" 883]
[org.eclipse.jetty.util.thread.QueuedThreadPool$Runner run "QueuedThreadPool.java" 1034]
[java.lang.Thread run nil -1]],
:cause "database is required for all queries whose type is not internal.",
:data
{:status-code 400,
:query
{:type "query",
:database nil,
:query {:source-table "card__127", :order-by [["desc" ["field" 1591 nil]]]},
:parameters [],
:middleware {:js-int-to-string? true}}},
:message "database is required for all queries whose type is not internal.",
:query
{:type "query",
:database nil,
:query {:source-table "card__127", :order-by [["desc" ["field" 1591 nil]]]},
:parameters [],
:middleware {:js-int-to-string? true}}}

Diagnostic info:
{
"browser-info": {
"language": "en-US",
"platform": "Win32",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0",
"vendor": ""
},
"system-info": {
"file.encoding": "UTF-8",
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.14.1+1",
"java.vendor": "Eclipse Adoptium",
"java.vendor.url": "https://adoptium.net/",
"java.version": "11.0.14.1",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.14.1+1",
"os.name": "Linux",
"os.version": "5.4.0-1063-azure",
"user.language": "en",
"user.timezone": "GMT"
},
"metabase-info": {
"databases": [
"sqlserver"
],
"hosting-env": "unknown",
"application-database": "postgres",
"application-database-details": {
"database": {
"name": "PostgreSQL",
"version": "11.12"
},
"jdbc-driver": {
"name": "PostgreSQL JDBC Driver",
"version": "42.2.23"
}
},
"run-mode": "prod",
"version": {
"date": "2022-04-07",
"tag": "v0.42.4",
"branch": "release-x.42.x",
"hash": "7c3ce2d"
},
"settings": {
"report-timezone": null
}
}
}

Hi @HadiHasan
That stacktrace is not related to anything that happens in Admin > Data Model.
Try describing your problem better or add steps-to-reproduce.

Created a Model [card__127] from admin side .. sorting working from admin side.. but for a user with only view permission the sorting is not working and showing the below error

and from the admin side the logs state the above stacktrace with query
query {:source-table "card__127", :order-by [["desc" ["field" 1591 nil]]]},

and message
** :message " database is required for all queries whose type is not internal .",**

@HadiHasan Okay, so you are using Models (https://www.metabase.com/docs/latest/users-guide/models.html).
You need to give data permissions if the users should be able to do actions.
We are working on preventing these errors by hiding the actions, which requires permissions.
For reference: https://github.com/metabase/metabase/pull/20320

The filters that is offered by the Model is not offered by the dashboard by default .. and giving permission to the users will allow them to gain more privileges that are not meant to be given for them in order to allow the sort and filter. What other alternative can we work on so that users with view privilege be able to sort and filter data without the option to add or edit or explore database

@HadiHasan I don't understand, but you can create a database View, which Metabase then recognize as a normal table.

you mean to create a view from the database not from metabase?

@HadiHasan Yes, create a View on the database. That is basically what Models is trying to mock in Metabase.