Should I use Model objects from library or make it myself?

45 Views Asked by At

I'm working with gitlab webhooks and I need to choose which data model to use in my project. I'm using the Python-gitlab library to work with gitlab, and this library has its own data models for all objects that use gitlab, for example, a merge request object from a webhook can be initialized as follows.

from gitlab.v4.objects.merge_requests import MergeRequest


async def webhook_data_handler(self, request: Request):
    webhook_mr_data: MergeRequest = MergeRequest(
        attrs=await request.json(),
        manager=RESTManager(gl=self.gitlab_cli)
    )
    print(webhook_mr_data.asdict())

But I also have pydantic in project and can make "my" model.

from pydantic import BaseModel


class MergeRequest(BaseModel):
    object_kind: str
    ... other fields ...

I have some, maybe a philosophical question, but I need to figure it out:

  1. My choice depends on which pydantic functionality I'm going to use? (e.g. validation, pre init func, etc.). If I don't need validation I should use gitlab-lib?
  2. Could it be correct to use gitlab-lib objects?
  3. How to make a choice in such situations, how to unambiguously say how to design the system correctly?

I tried creating pydantic model and gitlab model objects. And I didn't notice much difference, except that the pydantic model in the IDE can show model fields tip. In fact pydantic model I need write by my self, write fields and etc. In lib MergeRequest object can parse dict and make fields automaticly.

Sorry for noob question, but I what to figure it out.

At the first look answer suggests itself about the fact that since the work is happening with the gitlab and you need to use the already written functionality from the library, but I decided to clarify and ask for advice.

0

There are 0 best solutions below