question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integer array field in postgress is not handled by flask admin properly

See original GitHub issue

Integer array field in my table in postgres exists and work perfectly. I can create/apdate/insert/delete it with numbers. Flask-admin sees and interprets that field by SQLAlchemy model. Field shows up with its content in edit form in flask-admin. But whenever I try to save the form (regardless of editing or leaving contents of array field as is) I got error 500. Postgres throws an error: sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column "courses_ids" is of type integer[] but expression is of type text[] So it seems that flask-admin interprets my int array field as text array. Is there any solution on how to instruct Flask-Admin that the array field is of type int ?

Sqlalchemy field declaration: courses_ids = Column(ARRAY(Integer))

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:6

github_iconTop GitHub Comments

2reactions
aaron-nallcommented, Jul 15, 2019

A workaround:

class Select2IntegerTagsField(Select2TagsField):
    def process_formdata(self, valuelist):
        super().process_formdata(valuelist)
        self.data = [int(x) for x in self.data]


class StudentView(ModelView):
    def scaffold_form(self):
        form_class = super().scaffold_form()
        form_class.course_ids = Select2IntegerTagsField("Course Ids", save_as_list=True)
        return form_class

admin.add_view(StudentView(Student, session))
1reaction
Shir-Ariel-Havroncommented, Jun 27, 2020

A workaround:

class Select2IntegerTagsField(Select2TagsField):
    def process_formdata(self, valuelist):
        super().process_formdata(valuelist)
        self.data = [int(x) for x in self.data]


class StudentView(ModelView):
    def scaffold_form(self):
        form_class = super().scaffold_form()
        form_class.course_ids = Select2IntegerTagsField("Course Ids", save_as_list=True)
        return form_class

admin.add_view(StudentView(Student, session))

what is the Select2TagsField Class you’re inheriting from?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask-admin. Inlines form for items from postgres ARRAY
I would like to create InlineForm with wtf.fields.FileField for each item in pictures. Unfortunately I can't find the way for create inlines ...
Read more >
How to Use One-to-Many Database Relationships with Flask ...
In this tutorial, you'll build a small blogging system that demonstrates how to build one-to-many relationships using the Flask-SQLAlchemy ...
Read more >
Developing Python Web Applications with Flask
The app.run() launches the Flask's built-in development web server. It then waits for requests from clients, and handles the requests via the routes...
Read more >
Installation & Configuration - apache-superset - Read the Docs
Note that the development web server ( superset run or flask run ) is not intended ... as python-memcached does not handle storing...
Read more >
Using Python, Flask, and Angular to Build Modern Web Apps
TypeError: Field for "id" must be declared as a Field instance, not a class. Did you mean "fields.Number()"? I cloned your github repository...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found