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.

type object ... has no attribute ... when using formatters

See original GitHub issue

Hi, i’m using formatters for a model :

    column_formatters = {
        'name': macro('name_formatter')
    }

With its template :

{% macro name_formatter(model, column) %}
  {{ model.firstname }} {{ model.lastname }}
{% endmacro %}

Since flask-admin 1.4.1, i get this exception when running my application :

Traceback (most recent call last):
  File "run.py", line 2, in <module>
    from backend import app
  File "/path/to/project/backend/__init__.py", line 68, in <module>
    admin.create_admin(app)
  File "/path/to/project/backend/views/admin.py", line 204, in create_admin
    admin.add_view(OrderModelView(Order, db.session))
  File "/path/to/project/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 318, in __init__
    menu_icon_value=menu_icon_value)
  File "/path/to/project/lib/python2.7/site-packages/flask_admin/model/base.py", line 771, in __init__
    self._refresh_cache()
  File "/path/to/project/lib/python2.7/site-packages/flask_admin/model/base.py", line 847, in _refresh_cache
    self._list_columns = self.get_list_columns()
  File "/path/to/project/lib/python2.7/site-packages/flask_admin/model/base.py", line 980, in get_list_columns
    excluded_columns=self.column_exclude_list,
  File "/path/to/project/lib/python2.7/site-packages/flask_admin/contrib/sqla/view.py", line 517, in get_column_names
    column, path = tools.get_field_with_path(self.model, c)
  File "/path/to/project/lib/python2.7/site-packages/flask_admin/contrib/sqla/tools.py", line 144, in get_field_with_path
    value = getattr(current_model, attribute)
AttributeError: type object 'Order' has no attribute 'name'

Version 1.4.0 works well.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mrjoescommented, Jun 14, 2016

Ah! Now it makes sense. Never thought of using it that way.

OK, I’ll restore old behavior and release 1.4.2 with a bug fix today. I can’t think of better way of defining list of visible columns in one place even if they’re virtual.

0reactions
asfaltboycommented, Oct 7, 2016

@mrjoes I would just like to mention that this behavior does not seem to be documented; and, in my opinion is extremely useful for setting “virtual” fields. A simple use case:

class Person(db.Model):
    # ...
    first_name = db.Column(db.String(64))
    last_name = db.Column(db.String(64))

    @property
    def full_name(self):
        return '{p.first_name} {p.last_name}'.format(p=self)


class Person(sqla.ModelView):
    column_list = ('full_name', )
Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'NoneType' object has no attribute 'format'
Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
Read more >
raise ModuleAttributeError("'{}' object has no attribute ...
raise ModuleAttributeError("'{}' object has no attribute '{}'".format( torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'm' #1055.
Read more >
AttributeError: 'NoneType' object has no attribute 'format' - Reddit
Hi, I tried to make this loop work. But somehow I keep getting a NonType error. It seems that the format function fails...
Read more >
AttributeError: 'NoneType' object has no attribute 'format'
print ("Hello World") print ("{} World").format(Hello). I'm working on my first "Hello World" program and I can get it to work by using...
Read more >
Built-in Types — Python 3.11.1 documentation
Some operations are supported by several object types; in particular, ... Two more operations with the same syntactic priority, in and not in ......
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