# Buggy code
def issues(self):
    email = self.username
    # TODO -- doing something with blockedby would be nice.

    if self.query_url:
        query = self.bz.url_to_query(self.query_url)
        query["column_list"] = self.COLUMN_LIST
    else:
        query = dict(
            column_list=self.COLUMN_LIST,
            bug_status=self.open_statuses,
            email1=email,
            emailreporter1=1,
            emailassigned_to1=1,
            emailqa_contact1=1,
            emailtype1="substring",
        )

        if not self.ignore_cc:
            query["emailcc1"] = 1

    if self.advanced:
        # Required for new bugzilla
        # https://bugzilla.redhat.com/show_bug.cgi?id=825370
        query["query_format"] = "advanced"

    bugs = self.bz.query(query)

    if self.include_needinfos:
        needinfos = self.bz.query(
            dict(
                column_list=self.COLUMN_LIST,
                quicksearch="flag:needinfo?%s" % email,
            )
        )
        exists = [b.id for b in bugs]
        for bug in needinfos:
            # don't double-add bugs that have already been found
            if bug.id in exists:
                continue
            bugs.append(bug)

    # Convert to dicts
    bugs = [
        dict(((col, _get_bug_attr(bug, col)) for col in self.COLUMN_LIST))
        for bug in bugs
    ]

    issues = [(self.target, bug) for bug in bugs]
    log.debug(" Found %i total.", len(issues))

    # Build a url for each issue
    base_url = "https://%s/show_bug.cgi?id=" % (self.base_uri)
    for tag, issue in issues:
        issue_obj = self.get_issue_for_record(issue)
        extra = {
            "url": base_url + six.text_type(issue["id"]),
            "annotations": self.annotations(tag, issue, issue_obj),
        }

        needinfos = [
            f
            for f in issue["flags"]
            if (
                f["name"] == "needinfo"
                and f["status"] == "?"
                and f.get("requestee", self.username) == self.username
            )
        ]
        if needinfos:
            last_mod = needinfos[0]["modification_date"]
            # convert from RPC DateTime string to datetime.datetime object
            mod_date = datetime.datetime.fromtimestamp(
                time.mktime(last_mod.timetuple())
            )

            extra["needinfo_since"] = pytz.UTC.localize(mod_date)

        if issue["status"] == "ASSIGNED":
            extra["assigned_on"] = self._get_assigned_date(issue)
        else:
            extra["assigned_on"] = None

        issue_obj.update_extra(extra)
        yield issue_obj


# Traceback (TypeError)
Traceback (most recent call last):
File "/home/dave/dotfiles/external/pyenv/versions/bugwarrior/bin/bugwarrior-pull", line 8, in <module>
sys.exit(pull())
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/command.py", line 73, in pull
synchronize(issue_generator, config, main_section, dry_run)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/db.py", line 317, in synchronize
issue_dict = dict(issue)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 414, in keys
return list(self.__iter__())
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 409, in __iter__
record = self.get_taskwarrior_record()
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 305, in get_taskwarrior_record
self._taskwarrior_record = self.to_taskwarrior()
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/services/bz.py", line 83, in to_taskwarrior
task[self.NEEDINFO] = self.parse_date(self.extra.get('needinfo_since'))
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/bugwarrior/services/__init__.py", line 345, in parse_date
date = parse_date(date)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 1374, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 646, in parse
res, skipped_tokens = self._parse(timestr, **kwargs)
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 725, in _parse
l = _timelex.split(timestr)         # Splits the timestr into tokens
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 207, in split
return list(cls(s))
File "/home/dave/.pyenv/versions/2.7.18/envs/bugwarrior/lib/python2.7/site-packages/dateutil/parser/_parser.py", line 76, in __init__
'{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not datetime

# Fixed code
def issues(self):
    email = self.username
    # TODO -- doing something with blockedby would be nice.

    if self.query_url:
        query = self.bz.url_to_query(self.query_url)
        query["column_list"] = self.COLUMN_LIST
    else:
        query = dict(
            column_list=self.COLUMN_LIST,
            bug_status=self.open_statuses,
            email1=email,
            emailreporter1=1,
            emailassigned_to1=1,
            emailqa_contact1=1,
            emailtype1="substring",
        )

        if not self.ignore_cc:
            query["emailcc1"] = 1

    if self.advanced:
        # Required for new bugzilla
        # https://bugzilla.redhat.com/show_bug.cgi?id=825370
        query["query_format"] = "advanced"

    bugs = self.bz.query(query)

    if self.include_needinfos:
        needinfos = self.bz.query(
            dict(
                column_list=self.COLUMN_LIST,
                quicksearch="flag:needinfo?%s" % email,
            )
        )
        exists = [b.id for b in bugs]
        for bug in needinfos:
            # don't double-add bugs that have already been found
            if bug.id in exists:
                continue
            bugs.append(bug)

    # Convert to dicts
    bugs = [
        dict(((col, _get_bug_attr(bug, col)) for col in self.COLUMN_LIST))
        for bug in bugs
    ]

    issues = [(self.target, bug) for bug in bugs]
    log.debug(" Found %i total.", len(issues))

    # Build a url for each issue
    base_url = "https://%s/show_bug.cgi?id=" % (self.base_uri)
    for tag, issue in issues:
        issue_obj = self.get_issue_for_record(issue)
        extra = {
            "url": base_url + six.text_type(issue["id"]),
            "annotations": self.annotations(tag, issue, issue_obj),
        }

        needinfos = [
            f
            for f in issue["flags"]
            if (
                f["name"] == "needinfo"
                and f["status"] == "?"
                and f.get("requestee", self.username) == self.username
            )
        ]
        if needinfos:
            last_mod = needinfos[0]["modification_date"]
            # convert from RPC DateTime string to datetime.datetime object
            mod_date = datetime.datetime.fromtimestamp(
                time.mktime(last_mod.timetuple())
            )

            extra["needinfo_since"] = pytz.UTC.localize(mod_date).isoformat()

        if issue["status"] == "ASSIGNED":
            extra["assigned_on"] = self._get_assigned_date(issue)
        else:
            extra["assigned_on"] = None

        issue_obj.update_extra(extra)
        yield issue_obj