cherrypy + sqlalchemy + sqlalchemy-datatables: unhashable type: dict





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to integrate jQuery datatables server side processing with cherrypy & sqlalchemy, and I'm getting an error about "unhashable type: 'dict'".



The code I've written looks like this:



@cherrypy.tools.json_out()
def GET(self, *args, **kwargs):
with GetDb().ScopedSession("Fetching detail for main page") as session:
# defining columns
columns = [
ColumnDT(dbModels.DatabaseModel.Field1),
ColumnDT(dbModels.DatabaseModel.Field2),
# ...
]

query = session.query(dbModels.DatabaseModel)

# GET parameters
params = kwargs # I think this is what's causing the issue.

print("==========================")
print(params)
print("==========================")

# instantiating a DataTable for the query and table needed
rowTable = DataTables(params, query, columns)

# returns what is needed by DataTable
result = rowTable.output_result()
print("==========================")
print(result)
print("==========================")
return result


The result of the 'params' print looks like this (truncated somewhat):



{'draw': '1', 'columns[0][data]': '', 'columns[0][name]': '', 'columns[0][searchable]': 'true' } 


And the result output looks like this:



{'draw': '1', 'recordsTotal': '125', 'recordsFiltered': '125', 'error': "unhashable type: 'dict'"}


My suspicion is that the DataTables() call doesn't like the 'jsonpath'-like GET parameter (see the "# I think this is what's causing the issue" part above), so I'm curious if there's a way I can have cherrypy return the **kwargs as nested key/value pairs, or a function to convert kwargs into a nested dictionary -- or, if I'm completely wrong and this is a different error altogether. :)



Thanks!



More data if it helps:



The webpage rendering shows an alert saying:



DataTables warning: table id=active-jobs - unhashable type: 'dict'


Clicking OK yields a type error in the datatables code:



datatables.min.js:52 Uncaught TypeError: Cannot read property 'length' of undefined
at vb (datatables.min.js:52)
at datatables.min.js:49
at i (datatables.min.js:47)
at Object.success (datatables.min.js:48)
at fire (jquery-3.3.1.js:3268)
at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
at done (jquery-3.3.1.js:9305)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)
vb @ datatables.min.js:52
(anonymous) @ datatables.min.js:49
i @ datatables.min.js:47
success @ datatables.min.js:48
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
done @ jquery-3.3.1.js:9305
(anonymous) @ jquery-3.3.1.js:9548
load (async)
send @ jquery-3.3.1.js:9567
ajax @ jquery-3.3.1.js:9206
sa @ datatables.min.js:48
lb @ datatables.min.js:49
P @ datatables.min.js:41
T @ datatables.min.js:43
ha @ datatables.min.js:60
e @ datatables.min.js:105
(anonymous) @ datatables.min.js:105
each @ jquery-3.3.1.js:354
each @ jquery-3.3.1.js:189
n @ datatables.min.js:95
h.fn.DataTable @ datatables.min.js:177
RebuildTable @ (index):128
(anonymous) @ (index):266
mightThrow @ jquery-3.3.1.js:3534
process @ jquery-3.3.1.js:3602
setTimeout (async)
(anonymous) @ jquery-3.3.1.js:3640
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
fire @ jquery-3.3.1.js:3406
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
ready @ jquery-3.3.1.js:3878
completed @ jquery-3.3.1.js:3888









share|improve this question




















  • 3





    Please provide the full traceback, if any.

    – Ilja Everilä
    Nov 17 '18 at 7:27











  • There isn't one. This isn't excepting, the "unhashable type: 'dict'" is from the rowTable.output_result().

    – Eddie Parker
    Nov 19 '18 at 17:53











  • Well, upon further reflection, the javascript is causing a stack trace; so I'll add that to the description in case it's useful.

    – Eddie Parker
    Nov 19 '18 at 19:02


















0















I'm trying to integrate jQuery datatables server side processing with cherrypy & sqlalchemy, and I'm getting an error about "unhashable type: 'dict'".



The code I've written looks like this:



@cherrypy.tools.json_out()
def GET(self, *args, **kwargs):
with GetDb().ScopedSession("Fetching detail for main page") as session:
# defining columns
columns = [
ColumnDT(dbModels.DatabaseModel.Field1),
ColumnDT(dbModels.DatabaseModel.Field2),
# ...
]

query = session.query(dbModels.DatabaseModel)

# GET parameters
params = kwargs # I think this is what's causing the issue.

print("==========================")
print(params)
print("==========================")

# instantiating a DataTable for the query and table needed
rowTable = DataTables(params, query, columns)

# returns what is needed by DataTable
result = rowTable.output_result()
print("==========================")
print(result)
print("==========================")
return result


The result of the 'params' print looks like this (truncated somewhat):



{'draw': '1', 'columns[0][data]': '', 'columns[0][name]': '', 'columns[0][searchable]': 'true' } 


And the result output looks like this:



{'draw': '1', 'recordsTotal': '125', 'recordsFiltered': '125', 'error': "unhashable type: 'dict'"}


My suspicion is that the DataTables() call doesn't like the 'jsonpath'-like GET parameter (see the "# I think this is what's causing the issue" part above), so I'm curious if there's a way I can have cherrypy return the **kwargs as nested key/value pairs, or a function to convert kwargs into a nested dictionary -- or, if I'm completely wrong and this is a different error altogether. :)



Thanks!



More data if it helps:



The webpage rendering shows an alert saying:



DataTables warning: table id=active-jobs - unhashable type: 'dict'


Clicking OK yields a type error in the datatables code:



datatables.min.js:52 Uncaught TypeError: Cannot read property 'length' of undefined
at vb (datatables.min.js:52)
at datatables.min.js:49
at i (datatables.min.js:47)
at Object.success (datatables.min.js:48)
at fire (jquery-3.3.1.js:3268)
at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
at done (jquery-3.3.1.js:9305)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)
vb @ datatables.min.js:52
(anonymous) @ datatables.min.js:49
i @ datatables.min.js:47
success @ datatables.min.js:48
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
done @ jquery-3.3.1.js:9305
(anonymous) @ jquery-3.3.1.js:9548
load (async)
send @ jquery-3.3.1.js:9567
ajax @ jquery-3.3.1.js:9206
sa @ datatables.min.js:48
lb @ datatables.min.js:49
P @ datatables.min.js:41
T @ datatables.min.js:43
ha @ datatables.min.js:60
e @ datatables.min.js:105
(anonymous) @ datatables.min.js:105
each @ jquery-3.3.1.js:354
each @ jquery-3.3.1.js:189
n @ datatables.min.js:95
h.fn.DataTable @ datatables.min.js:177
RebuildTable @ (index):128
(anonymous) @ (index):266
mightThrow @ jquery-3.3.1.js:3534
process @ jquery-3.3.1.js:3602
setTimeout (async)
(anonymous) @ jquery-3.3.1.js:3640
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
fire @ jquery-3.3.1.js:3406
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
ready @ jquery-3.3.1.js:3878
completed @ jquery-3.3.1.js:3888









share|improve this question




















  • 3





    Please provide the full traceback, if any.

    – Ilja Everilä
    Nov 17 '18 at 7:27











  • There isn't one. This isn't excepting, the "unhashable type: 'dict'" is from the rowTable.output_result().

    – Eddie Parker
    Nov 19 '18 at 17:53











  • Well, upon further reflection, the javascript is causing a stack trace; so I'll add that to the description in case it's useful.

    – Eddie Parker
    Nov 19 '18 at 19:02














0












0








0








I'm trying to integrate jQuery datatables server side processing with cherrypy & sqlalchemy, and I'm getting an error about "unhashable type: 'dict'".



The code I've written looks like this:



@cherrypy.tools.json_out()
def GET(self, *args, **kwargs):
with GetDb().ScopedSession("Fetching detail for main page") as session:
# defining columns
columns = [
ColumnDT(dbModels.DatabaseModel.Field1),
ColumnDT(dbModels.DatabaseModel.Field2),
# ...
]

query = session.query(dbModels.DatabaseModel)

# GET parameters
params = kwargs # I think this is what's causing the issue.

print("==========================")
print(params)
print("==========================")

# instantiating a DataTable for the query and table needed
rowTable = DataTables(params, query, columns)

# returns what is needed by DataTable
result = rowTable.output_result()
print("==========================")
print(result)
print("==========================")
return result


The result of the 'params' print looks like this (truncated somewhat):



{'draw': '1', 'columns[0][data]': '', 'columns[0][name]': '', 'columns[0][searchable]': 'true' } 


And the result output looks like this:



{'draw': '1', 'recordsTotal': '125', 'recordsFiltered': '125', 'error': "unhashable type: 'dict'"}


My suspicion is that the DataTables() call doesn't like the 'jsonpath'-like GET parameter (see the "# I think this is what's causing the issue" part above), so I'm curious if there's a way I can have cherrypy return the **kwargs as nested key/value pairs, or a function to convert kwargs into a nested dictionary -- or, if I'm completely wrong and this is a different error altogether. :)



Thanks!



More data if it helps:



The webpage rendering shows an alert saying:



DataTables warning: table id=active-jobs - unhashable type: 'dict'


Clicking OK yields a type error in the datatables code:



datatables.min.js:52 Uncaught TypeError: Cannot read property 'length' of undefined
at vb (datatables.min.js:52)
at datatables.min.js:49
at i (datatables.min.js:47)
at Object.success (datatables.min.js:48)
at fire (jquery-3.3.1.js:3268)
at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
at done (jquery-3.3.1.js:9305)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)
vb @ datatables.min.js:52
(anonymous) @ datatables.min.js:49
i @ datatables.min.js:47
success @ datatables.min.js:48
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
done @ jquery-3.3.1.js:9305
(anonymous) @ jquery-3.3.1.js:9548
load (async)
send @ jquery-3.3.1.js:9567
ajax @ jquery-3.3.1.js:9206
sa @ datatables.min.js:48
lb @ datatables.min.js:49
P @ datatables.min.js:41
T @ datatables.min.js:43
ha @ datatables.min.js:60
e @ datatables.min.js:105
(anonymous) @ datatables.min.js:105
each @ jquery-3.3.1.js:354
each @ jquery-3.3.1.js:189
n @ datatables.min.js:95
h.fn.DataTable @ datatables.min.js:177
RebuildTable @ (index):128
(anonymous) @ (index):266
mightThrow @ jquery-3.3.1.js:3534
process @ jquery-3.3.1.js:3602
setTimeout (async)
(anonymous) @ jquery-3.3.1.js:3640
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
fire @ jquery-3.3.1.js:3406
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
ready @ jquery-3.3.1.js:3878
completed @ jquery-3.3.1.js:3888









share|improve this question
















I'm trying to integrate jQuery datatables server side processing with cherrypy & sqlalchemy, and I'm getting an error about "unhashable type: 'dict'".



The code I've written looks like this:



@cherrypy.tools.json_out()
def GET(self, *args, **kwargs):
with GetDb().ScopedSession("Fetching detail for main page") as session:
# defining columns
columns = [
ColumnDT(dbModels.DatabaseModel.Field1),
ColumnDT(dbModels.DatabaseModel.Field2),
# ...
]

query = session.query(dbModels.DatabaseModel)

# GET parameters
params = kwargs # I think this is what's causing the issue.

print("==========================")
print(params)
print("==========================")

# instantiating a DataTable for the query and table needed
rowTable = DataTables(params, query, columns)

# returns what is needed by DataTable
result = rowTable.output_result()
print("==========================")
print(result)
print("==========================")
return result


The result of the 'params' print looks like this (truncated somewhat):



{'draw': '1', 'columns[0][data]': '', 'columns[0][name]': '', 'columns[0][searchable]': 'true' } 


And the result output looks like this:



{'draw': '1', 'recordsTotal': '125', 'recordsFiltered': '125', 'error': "unhashable type: 'dict'"}


My suspicion is that the DataTables() call doesn't like the 'jsonpath'-like GET parameter (see the "# I think this is what's causing the issue" part above), so I'm curious if there's a way I can have cherrypy return the **kwargs as nested key/value pairs, or a function to convert kwargs into a nested dictionary -- or, if I'm completely wrong and this is a different error altogether. :)



Thanks!



More data if it helps:



The webpage rendering shows an alert saying:



DataTables warning: table id=active-jobs - unhashable type: 'dict'


Clicking OK yields a type error in the datatables code:



datatables.min.js:52 Uncaught TypeError: Cannot read property 'length' of undefined
at vb (datatables.min.js:52)
at datatables.min.js:49
at i (datatables.min.js:47)
at Object.success (datatables.min.js:48)
at fire (jquery-3.3.1.js:3268)
at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
at done (jquery-3.3.1.js:9305)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)
vb @ datatables.min.js:52
(anonymous) @ datatables.min.js:49
i @ datatables.min.js:47
success @ datatables.min.js:48
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
done @ jquery-3.3.1.js:9305
(anonymous) @ jquery-3.3.1.js:9548
load (async)
send @ jquery-3.3.1.js:9567
ajax @ jquery-3.3.1.js:9206
sa @ datatables.min.js:48
lb @ datatables.min.js:49
P @ datatables.min.js:41
T @ datatables.min.js:43
ha @ datatables.min.js:60
e @ datatables.min.js:105
(anonymous) @ datatables.min.js:105
each @ jquery-3.3.1.js:354
each @ jquery-3.3.1.js:189
n @ datatables.min.js:95
h.fn.DataTable @ datatables.min.js:177
RebuildTable @ (index):128
(anonymous) @ (index):266
mightThrow @ jquery-3.3.1.js:3534
process @ jquery-3.3.1.js:3602
setTimeout (async)
(anonymous) @ jquery-3.3.1.js:3640
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
fire @ jquery-3.3.1.js:3406
fire @ jquery-3.3.1.js:3268
fireWith @ jquery-3.3.1.js:3398
ready @ jquery-3.3.1.js:3878
completed @ jquery-3.3.1.js:3888






python datatables sqlalchemy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 19:02







Eddie Parker

















asked Nov 17 '18 at 7:23









Eddie ParkerEddie Parker

3,55422638




3,55422638








  • 3





    Please provide the full traceback, if any.

    – Ilja Everilä
    Nov 17 '18 at 7:27











  • There isn't one. This isn't excepting, the "unhashable type: 'dict'" is from the rowTable.output_result().

    – Eddie Parker
    Nov 19 '18 at 17:53











  • Well, upon further reflection, the javascript is causing a stack trace; so I'll add that to the description in case it's useful.

    – Eddie Parker
    Nov 19 '18 at 19:02














  • 3





    Please provide the full traceback, if any.

    – Ilja Everilä
    Nov 17 '18 at 7:27











  • There isn't one. This isn't excepting, the "unhashable type: 'dict'" is from the rowTable.output_result().

    – Eddie Parker
    Nov 19 '18 at 17:53











  • Well, upon further reflection, the javascript is causing a stack trace; so I'll add that to the description in case it's useful.

    – Eddie Parker
    Nov 19 '18 at 19:02








3




3





Please provide the full traceback, if any.

– Ilja Everilä
Nov 17 '18 at 7:27





Please provide the full traceback, if any.

– Ilja Everilä
Nov 17 '18 at 7:27













There isn't one. This isn't excepting, the "unhashable type: 'dict'" is from the rowTable.output_result().

– Eddie Parker
Nov 19 '18 at 17:53





There isn't one. This isn't excepting, the "unhashable type: 'dict'" is from the rowTable.output_result().

– Eddie Parker
Nov 19 '18 at 17:53













Well, upon further reflection, the javascript is causing a stack trace; so I'll add that to the description in case it's useful.

– Eddie Parker
Nov 19 '18 at 19:02





Well, upon further reflection, the javascript is causing a stack trace; so I'll add that to the description in case it's useful.

– Eddie Parker
Nov 19 '18 at 19:02












1 Answer
1






active

oldest

votes


















0














I finally figured this out. One of my columns was of type "JSONType" from sqlalchemy_utils, and the sqlalchemy-datatables class wasn't handling that it was getting a 'dict' back for the JSON data.



I solved this - for better or for worse - by not including that in my columns, and instead having a hand-crafted column that I filled an object out with the details that I needed.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349149%2fcherrypy-sqlalchemy-sqlalchemy-datatables-unhashable-type-dict%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I finally figured this out. One of my columns was of type "JSONType" from sqlalchemy_utils, and the sqlalchemy-datatables class wasn't handling that it was getting a 'dict' back for the JSON data.



    I solved this - for better or for worse - by not including that in my columns, and instead having a hand-crafted column that I filled an object out with the details that I needed.






    share|improve this answer




























      0














      I finally figured this out. One of my columns was of type "JSONType" from sqlalchemy_utils, and the sqlalchemy-datatables class wasn't handling that it was getting a 'dict' back for the JSON data.



      I solved this - for better or for worse - by not including that in my columns, and instead having a hand-crafted column that I filled an object out with the details that I needed.






      share|improve this answer


























        0












        0








        0







        I finally figured this out. One of my columns was of type "JSONType" from sqlalchemy_utils, and the sqlalchemy-datatables class wasn't handling that it was getting a 'dict' back for the JSON data.



        I solved this - for better or for worse - by not including that in my columns, and instead having a hand-crafted column that I filled an object out with the details that I needed.






        share|improve this answer













        I finally figured this out. One of my columns was of type "JSONType" from sqlalchemy_utils, and the sqlalchemy-datatables class wasn't handling that it was getting a 'dict' back for the JSON data.



        I solved this - for better or for worse - by not including that in my columns, and instead having a hand-crafted column that I filled an object out with the details that I needed.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 2 '18 at 4:50









        Eddie ParkerEddie Parker

        3,55422638




        3,55422638
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349149%2fcherrypy-sqlalchemy-sqlalchemy-datatables-unhashable-type-dict%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine