Skip to content

Conversation

k24d
Copy link

@k24d k24d commented Oct 18, 2015

I got an exception when I created a schedule with 'cron' = ''. This is a valid schedule meaning that the query is not scheduled to run.

In [1]: import tdclient

In [2]: c = tdclient.Client()

In [3]: c.create_schedule('test1', {'database': 'db1', 'cron': '', 'query': 'select 1'})
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-82b4b391c57e> in <module>()
----> 1 c.create_schedule('test1', {'database': 'db1', 'cron': '', 'query': 'select 1'})

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/tdclient/client.py in create_schedule(self, name, params)
    511             raise ValueError("'query' option is required")
    512         params = {} if params is None else params
--> 513         return self.api.create_schedule(name, params)
    514
    515     def delete_schedule(self, name):

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/tdclient/schedule_api.py in create_schedule(self, name, params)
     26                 self.raise_error("Create schedule failed", res, body)
     27             js = self.checked_json(body, ["start"])
---> 28             return self._parsedate(js["start"], "%Y-%m-%d %H:%M:%S %Z")
     29
     30     def delete_schedule(self, name):

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/tdclient/api.py in _parsedate(self, s, fmt)
    337         # TODO: parse datetime with using format string
    338         # for now, this ignores given format string since API may return date in ambiguous format :(
--> 339         return dateutil.parser.parse(s)
    340
    341     def get_or_else(self, hashmap, key, default_value=None):

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/dateutil/parser.py in parse(timestr, parserinfo, **kwargs)
   1006         return parser(parserinfo).parse(timestr, **kwargs)
   1007     else:
-> 1008         return DEFAULTPARSER.parse(timestr, **kwargs)
   1009
   1010

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/dateutil/parser.py in parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
    390             res, skipped_tokens = self._parse(timestr, **kwargs)
    391         else:
--> 392             res = self._parse(timestr, **kwargs)
    393
    394         if res is None:

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/dateutil/parser.py in _parse(self, timestr, dayfirst, yearfirst, fuzzy, fuzzy_with_tokens)
    490
    491         res = self._result()
--> 492         l = _timelex.split(timestr)         # Splits the timestr into tokens
    493
    494         # keep up with the last token skipped so we can recombine

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/dateutil/parser.py in split(cls, s)
    172
    173     def split(cls, s):
--> 174         return list(cls(s))
    175     split = classmethod(split)
    176

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/dateutil/parser.py in __next__(self)
    162
    163     def __next__(self):
--> 164         token = self.get_token()
    165         if token is None:
    166             raise StopIteration

/Users/knishida/miniconda/envs/pandas3/lib/python3.4/site-packages/dateutil/parser.py in get_token(self)
     80                 nextchar = self.charstack.pop(0)
     81             else:
---> 82                 nextchar = self.instream.read(1)
     83                 while nextchar == '\x00':
     84                     nextchar = self.instream.read(1)

AttributeError: 'NoneType' object has no attribute 'read'

With this patch, create_schedule returns '' (empty string) when cron is ''. There might be a better value than ''. The API probably should return a Python object or JSON object instead of start time, but it breaks compatibility.

In [1]: import tdclient

In [2]: c = tdclient.Client()

In [3]: c.create_schedule('test3', {'database': 'db1', 'cron': '', 'query': 'select 1'})
Out[3]: ''

@yyuu
Copy link
Member

yyuu commented Oct 18, 2015

Could you write some test for this if possible?

@k24d
Copy link
Author

k24d commented Oct 18, 2015

It turned out that a schedule object returns datetime.datetime(1970, 1, 1, 0, 0, tzinfo=tzutc()) when cron is ''. I'll change the returned object accordingly.

@landscape-bot
Copy link

Code Health
Code quality remained the same when pulling 414db9e on k24d:fix_create_schedule_without_start into bea9ba1 on treasure-data:master.

1 similar comment
@landscape-bot
Copy link

Code Health
Code quality remained the same when pulling 414db9e on k24d:fix_create_schedule_without_start into bea9ba1 on treasure-data:master.

yyuu added a commit that referenced this pull request Dec 12, 2015
avoid an exception raised when "start" is nil
@yyuu yyuu merged commit 68c4434 into treasure-data:master Dec 12, 2015
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

Successfully merging this pull request may close these issues.

3 participants