# Buggy code
def export_items():
    result = {
        "timestamp": datetime.utcnow().isoformat(),
        "scope": [
            {"target": item.target, "blacklist": item.blacklist, "tags": item.tags}
            for item in ScopeItem.getScope()
        ],
        "blacklist": [
            {"target": item.target, "blacklist": item.blacklist, "tags": item.tags}
            for item in ScopeItem.getBlacklist()
        ],
    }
    print(json.dumps(result, indent=2))


# Traceback (TypeError)
root@natlas:~# docker exec -ti natlas_server flask scope export
Sentry.io enabled and reporting errors to https://sentry.technowizardry.net
Traceback (most recent call last):
File "/.venv/bin/flask", line 8, in <module>
sys.exit(main())
File "/.venv/lib/python3.8/site-packages/flask/cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "/.venv/lib/python3.8/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/.venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/.venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/.venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/.venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/.venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/.venv/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/.venv/lib/python3.8/site-packages/flask/cli.py", line 426, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/.venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/natlas/natlas-server/app/cli/scope.py", line 79, in export_items
print(json.dumps(result, indent=2))
File "/usr/local/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/local/lib/python3.8/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/local/lib/python3.8/json/encoder.py", line 431, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/local/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/local/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/local/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
yield from chunks
File "/usr/local/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
yield from chunks
File "/usr/local/lib/python3.8/json/encoder.py", line 438, in _iterencode
o = _default(o)
File "/usr/local/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Tag is not JSON serializable

# Fixed code
def export_items():
    result = {
        "timestamp": datetime.utcnow().isoformat(),
        "scope": [
            {
                "target": item.target,
                "blacklist": item.blacklist,
                "tags": item.get_tag_names(),
            }
            for item in ScopeItem.getScope()
        ],
        "blacklist": [
            {
                "target": item.target,
                "blacklist": item.blacklist,
                "tags": item.get_tag_names(),
            }
            for item in ScopeItem.getBlacklist()
        ],
    }
    print(json.dumps(result, indent=2))