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

2D Array throws an error on GET #288

Closed
jbeard4 opened this issue Sep 24, 2020 · 5 comments
Closed

2D Array throws an error on GET #288

jbeard4 opened this issue Sep 24, 2020 · 5 comments

Comments

@jbeard4
Copy link
Contributor

jbeard4 commented Sep 24, 2020

Hello,

I have found that a column declaration like this:

db.Column(db.ARRAY(db.Float))

Which contains a 2D array (as is supported in, for example, Postgresql), yields an error on get:

  "message": "float() argument must be a string or a number, not 'list'"

Are 2D arrays supported by graphene-sqlalchemy?

Thank you for your help with this.

@jbeard4
Copy link
Contributor Author

jbeard4 commented Sep 24, 2020

I think the issue is here: https://github.com/graphql-python/graphene-sqlalchemy/blob/master/graphene_sqlalchemy/converter.py#L241

The SQLAlchemy dimensions property should be checked: https://docs-sqlalchemy.readthedocs.io/ko/latest/core/type_basics.html#sqlalchemy.types.ARRAY.params.dimensions

I would be happy to contribute this fix. Would you accept a patch for this?

Thank you for your time and attention to this issue.

jbeard4 added a commit to curvewise-forks/graphene-sqlalchemy that referenced this issue Sep 25, 2020
@wkevwang
Copy link

Facing this as well. Merging into the main repo would be really helpful!

@jbeard4
Copy link
Contributor Author

jbeard4 commented Apr 14, 2021

@wkevwang This project is not maintained. I recommend using PostGraphile instead.

@cglacet
Copy link

cglacet commented Mar 2, 2022

Seems like its still an issue today.

I used @jbeard4 patch and it works as expected.

from sqlalchemy import types
from graphene import List
from graphene_sqlalchemy import converter
from sqlalchemy.dialects import postgresql

def init_array_list_recursive(inner_type, n):
    return inner_type if n == 0 else List(init_array_list_recursive(inner_type, n-1))

@converter.convert_sqlalchemy_type.register(types.ARRAY)
@converter.convert_sqlalchemy_type.register(postgresql.ARRAY)
def convert_array_to_list(_type, column, registry=None):
    inner_type = converter.convert_sqlalchemy_type(column.type.item_type, column)
    return List(init_array_list_recursive(inner_type, (column.type.dimensions or 1) - 1))

converter.convert_array_to_list = convert_array_to_list

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants