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

[SQL Lab] timestamp with time zone field got AttributeError: 'NoneType' object has no attribute 'get' #3147

Closed
ernestoarbitrio opened this issue Jul 17, 2017 · 3 comments

Comments

@ernestoarbitrio
Copy link

I got AttributeError: 'NoneType' object has no attribute 'get' in SQL Lab only when I tried to get timezone fields with Fixed Timezone.

This is the sql table definition i'm trying to use

CREATE TABLE sales
(
  id serial NOT NULL,
  sale_date timestamp with time zone,
  id_item integer,
  id_store integer,
  receipt_number bigint,
  qty integer,
  net_value double precision,
  gross_value double precision,
  CONSTRAINT sales_pkey PRIMARY KEY (id),
  CONSTRAINT item_id_fk FOREIGN KEY (id_item)
      REFERENCES item (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED,
  CONSTRAINT store_id_fk FOREIGN KEY (id_store)
      REFERENCES store (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED
)

If i run a simple query in SQL Lab like SELECT id,qty FROM sales LIMIT 10 all was fine; but when i add the sale_date column in the fields SELECT id,qty,sale_date FROM sales LIMIT 10 this error appears:

  File "...../lib/python3.5/site-packages/superset/views/core.py", line 2055, in sql_json
    if data.get('status') == QueryStatus.FAILED:
AttributeError: 'NoneType' object has no attribute 'get'

The same query works fine through the psql client and also via sqlalchemy:

db=# select id,qty,sale_date from sales limit 10;
 id | qty |       sale_date
----+-----+------------------------
  1 |   1 | 2017-02-01 00:00:00+01
  2 |   1 | 2017-02-01 00:00:00+01
  3 |   1 | 2017-02-01 00:00:00+01
  4 |   1 | 2017-02-01 00:00:00+01
  5 |   1 | 2017-02-01 00:00:00+01
  6 |   1 | 2017-02-01 00:00:00+01
  7 |   1 | 2017-02-01 00:00:00+01
  8 |   1 | 2017-02-01 00:00:00+01
  9 |   1 | 2017-02-01 00:00:00+01
 10 |   1 | 2017-02-01 00:00:00+01
(10 rows)
>>> from sqlalchemy import text
>>> from sqlalchemy import create_engine
>>> eng = create_engine('postgresql://user:xxxxxxxxxx@host:port/mydb', echo=True)
>>> sql = text('select id,qty,sale_date from public.sales limit 10')
>>> res = eng.execute(sql)
>>> for r in res:
    ...:     print(r)
    ...:
(1, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(2, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(3, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(4, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(5, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(6, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(7, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(8, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(9, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))
(10, 1, datetime.datetime(2017, 2, 1, 0, 0, tzinfo=psycopg2.tz.FixedOffsetTimezone(offset=60, name=None)))

The only way to make it works in the SQL Lab is casting the sale_date field to char e.g.:

screen shot 2017-07-17 at 1 42 52 pm

otherwise

screen shot 2017-07-17 at 1 43 59 pm

Superset version: 0.18.5

Python: 3.5.2

DB Backend: PGSql with psycopg2 module

@ernestoarbitrio ernestoarbitrio changed the title timestamp with time zone field got AttributeError: 'NoneType' object has no attribute 'get' [SQL Lab] timestamp with time zone field got AttributeError: 'NoneType' object has no attribute 'get' Jul 17, 2017
@xrmx
Copy link
Contributor

xrmx commented Jul 17, 2017

Hi @ernestoarbitrio looks like this is a dup of #3144. Could you please give a try to #3111 and paste the new stacktrace?

@ernestoarbitrio
Copy link
Author

Oh @xrmx, sorry I didn't realize It was a dup of #3144. I'll try your PR ASAP. Thanks

@ernestoarbitrio
Copy link
Author

Great, the #3144 solves the problem.
TNKS

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

2 participants