Repository: openstates/openstates-scrapers

Issue:
WY failing since at least 2019-02-22
WY has been failing since 2019-02-22

Based on automated runs it appears that WY has not run successfully in 2 days (2019-02-22).


```
  KeyError: 'bill'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/opt/**PGUSER**/venv-pupa//bin/pupa", line 11, in <module>
    load_entry_point('pupa', 'console_scripts', 'pupa')()
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/cli/__main__.py", line 68, in main
    subcommands[args.subcommand].handle(args, other)
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/cli/commands/update.py", line 278, in handle
    return self.do_handle(args, other, juris)
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/cli/commands/update.py", line 329, in do_handle
    report['import'] = self.do_import(juris, args)
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/cli/commands/update.py", line 219, in do_import
    report.update(bill_importer.import_directory(datadir))
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/importers/base.py", line 196, in import_directory
    return self.import_data(json_stream())
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/importers/base.py", line 233, in import_data
    obj_id, what = self.import_item(data)
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/importers/base.py", line 279, in import_item
    updated = self._update_related(obj, related, self.related_models)
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/importers/base.py", line 367, in _update_related
    self._create_related(obj, {field: items}, subfield_dict)
  File "/opt/**PGUSER**/venv-pupa/src/pupa/pupa/importers/base.py", line 403, in _create_related
    raise DataImportError('{} while importing {} as {}'.format(e, subobjects, Subtype))
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/base.py", line 503, in __repr__
    return '<%s: %s>' % (self.__class__.__name__, self)
  File "/opt/**PGUSER**/venv-pupa/src/opencivicdata/opencivicdata/legislative/models/bill.py", line 102, in __str__
    return '{0} action on {1}'.format(self.bill.identifier, self.date)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 177, in __get__
    rel_obj = self.get_object(instance)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 144, in get_object
    return qs.get(self.field.get_reverse_related_filter(instance))
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/query.py", line 393, in get
    num = len(clone)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/query.py", line 250, in __len__
    self._fetch_all()
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1065, in execute_sql
    cursor.execute(sql, params)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/backends/utils.py", line 80, in _execute
    self.db.validate_no_broken_transaction()
  File "/opt/**PGUSER**/venv-pupa/lib/python3.6/site-packages/django/db/backends/base/base.py", line 437, in validate_no_broken_transaction
    "An error occurred in the current transaction. You can't "
django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
```

Visit http://bobsled.openstates.org for more info.



Discussion:

Resolving patch:
diff --git a/openstates/wy/bills.py b/openstates/wy/bills.py
--- a/openstates/wy/bills.py
+++ b/openstates/wy/bills.py
@@ -268,6 +268,9 @@ def parse_local_date(self, date_str):
             date_str = date_str + '.0'
 
         date_obj = datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S.%f')
+        # Truncate microseconds; opencivicdata limits action date to 25 characters
+        # TODO: Fix in opencivicdata
+        date_obj = date_obj.replace(microsecond=0)
         local_date = TIMEZONE.localize(date_obj)
         utc_action_date = local_date.astimezone(pytz.utc)
         return utc_action_date


Test patch: