Issue: Problems with Peewee and Python 3.8
Author: Petesta
State: closed
Created: 2020-08-26 22:41:34

I currently have a working implementation running on `Python 3.6` running `peewee 3.13.3` and `psycopg2-binary 2.8.5` with `Postgres 9.6`. I upgraded the Python runtime to `Python 3.8` and started receiving this error.

```
[ERROR] Exception: Your version of psycopg2 does not support JSON.
Traceback (most recent call last):
  File "/var/lang/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/db/models.py", line 25, in <module>
    class MyModel(ModelBase):
  File "/var/task/db/models.py", line 31, in MyModel
    response = BinaryJSONField(null=True)
  File "/var/task/playhouse/postgres_ext.py", line 163, in __init__
    super(IndexedFieldMixin, self).__init__(*args, **kwargs)
  File "/var/task/playhouse/postgres_ext.py", line 300, in __init__
    raise Exception('Your version of psycopg2 does not support JSON.')
```

Here is the code.

```python
from playhouse.postgres_ext import BinaryJSONField

class MyModel(ModelBase):
    class Meta:
        table_name = "my_models"
    response = BinaryJSONField(null=True)
```

I checked the source code inside of `postgres_ext.py` and from what I can see it looks like it should work based on this [import statement](https://github.com/coleifer/peewee/blob/master/playhouse/postgres_ext.py#L29-L32). Have any idea why this would cause an issue? I reverted back to `Python 3.6` and the problem was resolved.

You probably need to re-install psycopg2. Peewee is reporting that it found psycopg2 but that json support was not present. https://www.psycopg.org/docs/extras.html#json-adaptation

@coleifer I have already tried reinstalling the packages `psycopg2` and `psycopg2-binary` together and separately, prior to opening up an issue, to see if it would help and nothing changed. I've spun up new instances and still have the same problem. Again this only happens once the runtime is changed from `3.6` to `3.8` and new environments have been tried.

Peewee says to use this [class PostgresqlExtDatabase](http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#PostgresqlExtDatabase) and it has server side cursors readily available for json. The version that is running at runtime is `2.8.5` for `psycopg2`.

I've been using this library with no problem for over four years, thanks for the work, and it seemed odd to me that an upgrade of the runtime would cause an issue. We can see at runtime the necessary libraries are loaded and on the load path.

Something doesn't add up in what you're describing. You stated that all you changed is your python runtime, but I'm telling you that I think you're missing something on your end.

Peewee only reports that error if your psycopg2 does not export the Json helper. You can verify:

```python

In [1]: import sys; sys.version_info                                                            
Out[1]: sys.version_info(major=3, minor=8, micro=0, releaselevel='final', serial=0)

In [2]: from playhouse.postgres_ext import Json                                                 

In [3]: Json                                                                                    
Out[3]: psycopg2._json.Json
```