{"action":"created","issue":{"url":"https://api.github.com/repos/ckan/ckan/issues/1789","repository_url":"https://api.github.com/repos/ckan/ckan","labels_url":"https://api.github.com/repos/ckan/ckan/issues/1789/labels{/name}","comments_url":"https://api.github.com/repos/ckan/ckan/issues/1789/comments","events_url":"https://api.github.com/repos/ckan/ckan/issues/1789/events","html_url":"https://github.com/ckan/ckan/issues/1789","id":36306323,"number":1789,"title":"Modifying resource schema can cause a failure when indexing the package","user":{"login":"rossjones","id":118063,"avatar_url":"https://avatars.githubusercontent.com/u/118063?v=3","gravatar_id":"","url":"https://api.github.com/users/rossjones","html_url":"https://github.com/rossjones","followers_url":"https://api.github.com/users/rossjones/followers","following_url":"https://api.github.com/users/rossjones/following{/other_user}","gists_url":"https://api.github.com/users/rossjones/gists{/gist_id}","starred_url":"https://api.github.com/users/rossjones/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rossjones/subscriptions","organizations_url":"https://api.github.com/users/rossjones/orgs","repos_url":"https://api.github.com/users/rossjones/repos","events_url":"https://api.github.com/users/rossjones/events{/privacy}","received_events_url":"https://api.github.com/users/rossjones/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/ckan/ckan/milestones/6","html_url":"https://github.com/ckan/ckan/milestones/CKAN%202.4%20(old)","labels_url":"https://api.github.com/repos/ckan/ckan/milestones/6/labels","id":834156,"number":6,"title":"CKAN 2.4 (old)","description":"","creator":{"login":"amercader","id":200230,"avatar_url":"https://avatars.githubusercontent.com/u/200230?v=3","gravatar_id":"","url":"https://api.github.com/users/amercader","html_url":"https://github.com/amercader","followers_url":"https://api.github.com/users/amercader/followers","following_url":"https://api.github.com/users/amercader/following{/other_user}","gists_url":"https://api.github.com/users/amercader/gists{/gist_id}","starred_url":"https://api.github.com/users/amercader/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amercader/subscriptions","organizations_url":"https://api.github.com/users/amercader/orgs","repos_url":"https://api.github.com/users/amercader/repos","events_url":"https://api.github.com/users/amercader/events{/privacy}","received_events_url":"https://api.github.com/users/amercader/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":144,"state":"closed","created_at":"2014-10-21T10:10:31Z","updated_at":"2016-05-10T17:36:17Z","due_on":null,"closed_at":"2016-03-17T11:27:20Z"},"comments":3,"created_at":"2014-06-23T16:16:28Z","updated_at":"2016-05-24T11:26:07Z","closed_at":"2016-05-10T17:35:50Z","body":"Using IPackageController and modifying the schema, I have the following code to change the metadata for the resource.\r\n\r\n``` python\r\n    resource_schema = default_resource_schema()\r\n    resource_schema.update({\r\n        u'update_frequency': [\r\n                tk.get_converter('convert_from_extras'),\r\n                valid_update_frequency,\r\n                tk.get_validator('ignore_missing'),\r\n        ],\r\n    .... more junk removed\r\n\r\n    schema['resources'] = resource_schema\r\n```\r\nNow however when I save the resource being edited I get the following stack trace\r\n\r\n```\r\n... irrelevant junk removed\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/model/modification.py', line 72 in before_commit\r\n  self.notify(obj, domain_object.DomainObjectOperation.changed)\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/model/modification.py', line 79 in notify\r\n  observer.notify(entity, operation)\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/lib/search/__init__.py', line 129 in notify\r\n  operation\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/lib/search/__init__.py', line 103 in dispatch_by_operation\r\n  index.update_dict(entity)\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/lib/search/index.py', line 104 in update_dict\r\n  self.index_package(pkg_dict, defer_commit)\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/lib/search/index.py', line 121 in index_package\r\n  cls=ckan.lib.navl.dictization_functions.MissingNullEncoder)\r\nFile '/usr/lib/python2.7/json/__init__.py', line 238 in dumps\r\n  **kw).encode(obj)\r\nFile '/usr/lib/python2.7/json/encoder.py', line 201 in encode\r\n  chunks = self.iterencode(o, _one_shot=True)\r\nFile '/usr/lib/python2.7/json/encoder.py', line 264 in iterencode\r\n  return _iterencode(o, 0)\r\nFile '/var/www/tenants/dev2/ckan/src/ckan/ckan/lib/navl/dictization_functions.py', line 418 in default\r\n  return json.JSONEncoder.default(self, obj)\r\nFile '/usr/lib/python2.7/json/encoder.py', line 178 in default\r\n  raise TypeError(repr(o) + \" is not JSON serializable\")\r\nTypeError: datetime.datetime(2014, 6, 17, 16, 19, 57, 342863) is not JSON serializable\r\n```\r\nThis is the ```created``` field of the resource.\r\n\r\nThe problem seems to be one or both of:\r\n\r\na. The validator/converter for resources doesn't seem to get run if you have modified the resource schema (even if I re-insert it).\r\nb. MissingNullEncoder doesn't handle being passed datetimes, and it should.\r\n\r\nI fixed this myself with the following code because I can't wait for 2.3 :(\r\n\r\n```python\r\nimport ckan.lib.navl.dictization_functions as df\r\n# Monkeypatchtastic\r\nclass DateHandlingMissingNullEncoder(json.JSONEncoder):\r\n    '''json encoder that treats missing objects as null'''\r\n    def default(self, obj):\r\n        if isinstance(obj, df.Missing):\r\n            return None\r\n        elif isinstance(obj, datetime.datetime):\r\n            return obj.isoformat()\r\n        return json.JSONEncoder.default(self, obj)\r\n\r\ndf.MissingNullEncoder = DateHandlingMissingNullEncoder\r\n```"},"comment":{"url":"https://api.github.com/repos/ckan/ckan/issues/comments/221240654","html_url":"https://github.com/ckan/ckan/issues/1789#issuecomment-221240654","issue_url":"https://api.github.com/repos/ckan/ckan/issues/1789","id":221240654,"user":{"login":"davidread","id":307612,"avatar_url":"https://avatars.githubusercontent.com/u/307612?v=3","gravatar_id":"","url":"https://api.github.com/users/davidread","html_url":"https://github.com/davidread","followers_url":"https://api.github.com/users/davidread/followers","following_url":"https://api.github.com/users/davidread/following{/other_user}","gists_url":"https://api.github.com/users/davidread/gists{/gist_id}","starred_url":"https://api.github.com/users/davidread/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidread/subscriptions","organizations_url":"https://api.github.com/users/davidread/orgs","repos_url":"https://api.github.com/users/davidread/repos","events_url":"https://api.github.com/users/davidread/events{/privacy}","received_events_url":"https://api.github.com/users/davidread/received_events","type":"User","site_admin":false},"created_at":"2016-05-24T11:26:07Z","updated_at":"2016-05-24T11:26:07Z","body":"This issue was closed due to inactivity. Feel free to reopen if you have more feedback or are interested it working on it"}}
{"actor":{"display_login":"davidread"}}