flask-restless
flask-restless copied to clipboard
API endpoint hitting a table that doesn't exist nor configured
I have most of my SQLAlchemy models setup quite similarly but flask-restless is querying "tag" which is a table that doesn't exist nor do I have it configured anywhere in my project.
Endpoint:
restless_manager.create_api(
tumbleweed_db.TumbleweedTag,
url_prefix='/api/v1',
collection_name='post_tag',
methods=['GET', 'POST', 'PUT', 'PATCH']
)
Model:
class TumbleweedTag(db.Model, CustomBase):
__bind_key__ = 'tumbleweed'
__tablename__ = 'tumbleweed_tag'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(convert_unicode=True, length=255, collation='utf8mb4_unicode_ci'), index=True,
nullable=False, unique=True)
def __init__(self, **kwargs):
for c in self.__table__.columns:
c_data = kwargs.pop(c.key, None)
if c_data:
setattr(self, c.key, c_data)
if kwargs:
raise AttributeError('Found unexpected keywords: {}'.format(', '.join(kwargs.iterkeys())))
def __repr__(self):
return str('<{} id={}, name={}>').format(self.__class__.__name__, self.id, self.name)
As you can see, via the aforementioned, the table name is not "tag". I've tried changing the endpoint names from tag to post_tag to alsdfkhjalsfk and it queries the wrong table. I need to test my other endpoints but I so far I have not seen this problem appear anywhere else.
Logging:
* Debugger is active!
* Debugger pin code: 189-087-841
2016-07-06 10:08:33,740 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2016-07-06 10:08:33,740 INFO sqlalchemy.engine.base.Engine SELECT tag.id AS tag_id, tag.name AS tag_name
FROM tag ORDER BY tag.id ASC
LIMIT %s, %s
2016-07-06 10:08:33,740 INFO sqlalchemy.engine.base.Engine (0, 10)
2016-07-06 10:08:33,785 INFO sqlalchemy.engine.base.Engine SELECT tag.id AS tag_id, tag.name AS tag_name
FROM tag ORDER BY tag.id ASC
2016-07-06 10:08:33,785 INFO sqlalchemy.engine.base.Engine ()
2016-07-06 10:08:33,848 INFO sqlalchemy.engine.base.Engine ROLLBACK
127.0.0.1 - - [06/Jul/2016 10:08:33] "GET /api/v1/tag HTTP/1.1" 200 -
--------------------------------------------------------------------------------
PATH: '/api/v1/tag'
6807 function calls (6679 primitive calls) in 0.157 seconds
Ordered by: internal time, call count
List reduced from 848 to 30 due to restriction <30>
ncalls tottime percall cumtime percall filename:lineno(function)
2 0.096 0.048 0.096 0.048 {method 'query' of '_mysql.connection' objects}
1 0.044 0.044 0.044 0.044 {method 'rollback' of '_mysql.connection' objects}
1 0.003 0.003 0.006 0.006 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/idna.py:3(<module>)
1 0.001 0.001 0.001 0.001 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/stringprep.py:6(<module>)
2 0.001 0.000 0.001 0.001 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sre_compile.py:256(_optimize_charset)
2 0.001 0.000 0.006 0.003 {__import__}
116 0.000 0.000 0.001 0.000 {method 'sort' of 'list' objects}
181 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/routing.py:856(match_compare_key)
15 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/sqlalchemy/event/attr.py:123(update_subclass)
21/2 0.000 0.000 0.000 0.000 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py:148(__subclasscheck__)
10 0.000 0.000 0.000 0.000 {method 'find' of 'bytearray' objects}
181 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/routing.py:872(build_compare_key)
209 0.000 0.000 0.007 0.000 {getattr}
1 0.000 0.000 0.044 0.044 /Library/Python/2.7/site-packages/sqlalchemy/engine/base.py:1599(_do_rollback)
181 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/routing.py:1340(<lambda>)
347/346 0.000 0.000 0.001 0.000 {is instance
34 0.000 0.000 0.006 0.000 {method 'decode' of 'str' objects}
50 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/local.py:160(top)
1 0.000 0.000 0.001 0.001 /Library/Python/2.7/site-packages/werkzeug/routing.py:1425(match)
81 0.000 0.000 0.001 0.000 {hasattr}
181 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/routing.py:1342(<lambda>)
6 0.000 0.000 0.000 0.000 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py:243(__init__)
179 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/routing.py:744(match)
2 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/flask_sqlalchemy/__init__.py:121(_calling_context)
1 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/werkzeug/urls.py:847(url_join)
2 0.000 0.000 0.097 0.049 /Library/Python/2.7/site-packages/sqlalchemy/engine/base.py:1061(_execute_context)
647 0.000 0.000 0.000 0.000 {len}
2 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/sqlalchemy/orm/loading.py:224(_setup_entity_query)
2 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/sqlalchemy/orm/loading.py:269(_instance_processor)
98/58 0.000 0.000 0.000 0.000 /Library/Python/2.7/site-packages/simplejson/encoder.py:536(_iterencode_dict)
--------------------------------------------------------------------------------