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

Querying API on column that does not exist returns all records #149

Open
narzeja opened this issue Sep 1, 2014 · 0 comments
Open

Querying API on column that does not exist returns all records #149

narzeja opened this issue Sep 1, 2014 · 0 comments

Comments

@narzeja
Copy link

narzeja commented Sep 1, 2014

Querying the flask_peewee API for columns that does not exist, returns all records from the table, instead of an empty set and/or an error that the supplied column name does not exist.

Consider the following code:

from flask import Flask
from peewee import *
from flask_peewee.rest import RestAPI
from datetime import datetime

app = Flask(__name__)
api = RestAPI(app)

class MyUser(Model):
    username = CharField(45, unique=True)
    admin = BooleanField(default=True)
    join_date = DateTimeField(default=datetime.now)
    email = CharField(145)
    class Meta:
        database = SqliteDatabase('mydb.sqlite')

try:
    MyUser.create_table()
    MyUser.create(username='test',
                  admin=True,
                  email='[email protected]')
    MyUser.create(username='test2',
                  admin=False,
                  email='[email protected]')
    MyUser.create(username='test3',
                  admin=False,
                  email='[email protected]')
except:
    pass

api.register(MyUser, allowed_methods=['GET'])
api.setup()

if __name__ == "__main__":
    app.run()

Launching the app, I can now query the API:

curl http://localhost:5000/api/myuser/?name=cheese

Notice, that the 'name' column does not exist in the table. This query returns a paginated result of all records in the table, instead of an (expected) notification that the column is invalid and/or an empty result set.

Using the latest version (0.6.5) installed from pip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant