Skip to content

ProjectLabel objects are not JSON serializable聽#1116

Closed

Description

@MatthieuPERIN

Description of the problem, including code/CLI snippet

Idea is to use Gitlab-Python to manage Labels in numerous project in a more scallable way 馃槄

MWE

# setup gl-py
gl = gitlab.Gitlab(GITLAB_ADRESS, private_token=TOKEN, ssl_verify=False)
gl.auth()

#get the project
src_prj = gl.projects.get(SRC_PRJ_ID)

# try to serialize the first Label Project
with open('data.txt', 'w') as outfile:
    json.dump(src_prj.labels.list(all=True)[0], outfile)

Get the following

Traceback (most recent call last):
  File "C:/Users/MPERIN/Git/labelautomation/labelmodel.py", line 79, in <module>
    json.dump(src_prj.labels.list(all=True)[0], outfile)
  File "C:\Users\MPERIN\AppData\Local\Continuum\miniconda3\envs\labelautomation\lib\json\__init__.py", line 179, in dump
    for chunk in iterable:
  File "C:\Users\MPERIN\AppData\Local\Continuum\miniconda3\envs\labelautomation\lib\json\encoder.py", line 438, in _iterencode
    o = _default(o)
  File "C:\Users\MPERIN\AppData\Local\Continuum\miniconda3\envs\labelautomation\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ProjectLabel is not JSON serializable

Expected Behavior

The Gilabl-python object are well serialized into JSON

Actual Behavior

The serialization crashes 馃槖

Specifications

  • python-gitlab version: 2.2 (pip)
  • API version you are using (v3/v4): v4
  • Gitlab server version (or gitlab.com): 11.10.0

Activity

  1. max-wittig commented on Jun 15, 2020

    @max-wittig
    Member

    You can always request the .attributes of an objects. That should be json serializable, but I guess it would make sense for all projects to be serializable.

    Btw. your GitLab version is not supported by python-gitlab and it's dangerous to use. No security whatsoever, all vulnerabilities of it are public. You should upgrade to 13.0.0

  2. MatthieuPERIN commented on Jun 15, 2020

    @MatthieuPERIN
    Author

    @max-wittig Thanks for the solution on .attributes and yes a "builtin" solution would be nicer

    Agree for the GitLab version but this is a corporate internal-only use forge pending upgrade to 13.X pending (long-due) hardware migration (always the same music it seems).

  3. max-wittig commented on Jun 15, 2020

    @max-wittig
    Member

    @MatthieuPERIN Maybe you should raise some security concerns and include this page with all vulnabilities 馃槃 https://hackerone.com/gitlab/hacktivity

  4. changed the title [-]ProjetcLabel object are not JSON serializable[/-] [+]ProjectLabel objects are not JSON serializable[/+] on Feb 2, 2022
  5. JohnVillalovos commented on Feb 2, 2022

    @JohnVillalovos
    Member

    I have proposed #1872 that would allow you to serialize the objects.

    If merged it would allow:

    # try to serialize the first Label Project
    with open('data.txt', 'w') as outfile:
        json.dump(src_prj.labels.list(all=True)[0].asdict(), outfile)
    

    Maybe ignore this for now as I was not aware of attributes property...

  6. added 9 commits that reference this issue on Jul 6, 2022
    973e68f
    8593e8a
    599c906
    3297ca4
    4b600ff
    ef5aed2
    ec643b7
    a636938
    08ac071
  7. locked as resolved and limited conversation to collaborators on Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions