Skip to content

Commit

Permalink
Fix: Return wrong query syntax "SELECT FROM" when no tags and fields
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquan committed Nov 26, 2017
1 parent 7d4913a commit 444f7ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion influxalchemy/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def _select(self):
selects.append(field)
# pylint: disable=bare-except
except:
selects = ["*"]
pass
if not selects:
selects = ["*"]
return selects

@property
Expand Down
12 changes: 12 additions & 0 deletions tests/query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,15 @@ def test_get_tags_fields(mock_fields, mock_tags):
fizz = Measurement.new("fuzz")
query = client.query(fizz)
assert str(query) == "SELECT fizz, buzz, foo, goo FROM fuzz;"


@mock.patch("influxalchemy.InfluxAlchemy.tags")
@mock.patch("influxalchemy.InfluxAlchemy.fields")
def test_get_empty_tags_fields(mock_fields, mock_tags):
mock_tags.return_value = []
mock_fields.return_value = []
db = influxdb.InfluxDBClient(database="example")
client = InfluxAlchemy(db)
fizz = Measurement.new("fuzz")
query = client.query(fizz)
assert str(query) == "SELECT * FROM fuzz;"

0 comments on commit 444f7ea

Please sign in to comment.