Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pydantic version #2246

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def main():

# Dispatch handler.
args = parser.parse_args()
if hasattr(args, "env_file") and Path(args.env_file).is_file():
if hasattr(args, "env_file") and args.env_file and Path(args.env_file).is_file():
env.read_env(args.env_file, recurse=False, override=True)
if hasattr(args, "handler"):
django.setup()
Expand Down
20 changes: 8 additions & 12 deletions backend/data_import/pipeline/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import uuid
from typing import Any, Optional

from pydantic import UUID4, BaseModel, ConstrainedStr, NonNegativeInt, root_validator
from pydantic import UUID4, BaseModel, NonNegativeInt, constr, root_validator

from .label_types import LabelTypes
from examples.models import Example
Expand All @@ -15,10 +15,6 @@
from projects.models import Project


class NonEmptyStr(ConstrainedStr):
min_length = 1


class Label(BaseModel, abc.ABC):
id: int = -1
uuid: UUID4
Expand Down Expand Up @@ -49,14 +45,14 @@ def __hash__(self):


class CategoryLabel(Label):
label: NonEmptyStr
label: constr(min_length=1) # type: ignore

def __lt__(self, other):
return self.label < other.label

@classmethod
def parse(cls, example_uuid: UUID4, obj: Any):
return cls(example_uuid=example_uuid, label=obj)
return cls(example_uuid=example_uuid, label=obj) # type: ignore

def create_type(self, project: Project) -> Optional[LabelType]:
return CategoryType(text=self.label, project=project)
Expand All @@ -66,14 +62,14 @@ def create(self, user, example: Example, types: LabelTypes, **kwargs):


class SpanLabel(Label):
label: NonEmptyStr
label: constr(min_length=1) # type: ignore
start_offset: NonNegativeInt
end_offset: NonNegativeInt

def __lt__(self, other):
return self.start_offset < other.start_offset

@root_validator
@root_validator(skip_on_failure=True)
def check_start_offset_is_less_than_end_offset(cls, values):
start_offset, end_offset = values.get("start_offset"), values.get("end_offset")
if start_offset >= end_offset:
Expand Down Expand Up @@ -105,14 +101,14 @@ def create(self, user, example: Example, types: LabelTypes, **kwargs):


class TextLabel(Label):
text: NonEmptyStr
text: constr(min_length=1) # type: ignore

def __lt__(self, other):
return self.text < other.text

@classmethod
def parse(cls, example_uuid: UUID4, obj: Any):
return cls(example_uuid=example_uuid, text=obj)
return cls(example_uuid=example_uuid, text=obj) # type: ignore

def create_type(self, project: Project) -> Optional[LabelType]:
return None
Expand All @@ -124,7 +120,7 @@ def create(self, user, example: Example, types: LabelTypes, **kwargs):
class RelationLabel(Label):
from_id: int
to_id: int
type: NonEmptyStr
type: constr(min_length=1) # type: ignore

def __lt__(self, other):
return self.from_id < other.from_id
Expand Down