Repository: ckan/ckan

Issue:
The API method license_list no longer works with CKAN 2.10.0
## CKAN Version
2.10.0

## Describe the bug
Calling the API method `license_list` causes an error since version 2.10.0.

### Steps to reproduce
Calling the API `/api/action/license_list`.

### Expected behavior
Returns the list of the licenses.

### Additional details
The error happens in this line of code: https://github.com/ckan/ckan/blob/master/ckan/logic/action/get.py#L762. The function `License.as_dict()`  is being called which was removed with commit: https://github.com/ckan/ckan/commit/6937dc800366118426ce7ba9529e1523e4ef13f2
```
ERROR [ckan.views.api] as_dict
Traceback (most recent call last):
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/model/license.py", line 37, in __getattr__
    return self._data[name]
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/model/license.py", line 186, in __getitem__
    raise KeyError(key)
KeyError: 'as_dict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/config/middleware/../../views/api.py", line 283, in action
    result = function(context, request_data)
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/logic/__init__.py", line 551, in wrapped
    result = _action(context, data_dict, **kw)
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/logic/action/get.py", line 762, in license_list
    licenses = [l.as_dict() for l in licenses]
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/logic/action/get.py", line 762, in <listcomp>
    licenses = [l.as_dict() for l in licenses]
  File "/usr/lib/ckan/env/lib/python3.9/site-packages/ckan/model/license.py", line 41, in __getattr__
    raise AttributeError(*e.args)
AttributeError: as_dict
```

We solved the problem by re-adding the function `as_dict()`:
```
def as_dict(self):
        '''This method is still used in the logic of the action API 'license_list'. 
           Please use attribute access preferably.'''
        return self._data.copy()
```
Shall we provide a pull request with re-adding the function or is there a better solution?


Discussion:

Resolving patch:
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -759,7 +759,7 @@ def license_list(context: Context, data_dict: DataDict) -> ActionResult.LicenseL
 
     license_register = model.Package.get_license_register()
     licenses = license_register.values()
-    licenses = [l.as_dict() for l in licenses]
+    licenses = [l.license_dictize() for l in licenses]
     return licenses
 
 
diff --git a/ckan/model/license.py b/ckan/model/license.py
--- a/ckan/model/license.py
+++ b/ckan/model/license.py
@@ -46,6 +46,14 @@ def isopen(self) -> bool:
                 self.osd_conformance == 'approved'
         return self._isopen
 
+    def license_dictize(self) -> dict[str, Any]:
+        data = self._data.copy()
+        if 'date_created' in data:
+            value = data['date_created']
+            value = value.isoformat()
+            data['date_created'] = value
+        return data
+
 
 class LicenseRegister(object):
     """Dictionary-like interface to a group of licenses."""


Test patch: