Skip to content

Commit

Permalink
chore: Align model with model_id nullability, except Application.lend…
Browse files Browse the repository at this point in the history
…er non-nullable (like .credit_product since b3d05bf)

SQLModel would suggests making these two nullable, but doing so causes type errors. Making them non-nullable doesn't affect migrations or validation, since Application is not used as a request or response format.

https://sqlmodel.tiangolo.com/tutorial/relationship-attributes/define-relationships-attributes/#optional-relationship-attributes
  • Loading branch information
jpmckinney committed Aug 23, 2024
1 parent 2ccc9be commit 2c50d42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
mypy --strict --show-error-codes app reportlab_mods.py > error-summary.txt
status=$?
cat error-summary.txt
[ $status -eq 0 ] || [ $(tail -n1 error-summary.txt | cut -d' ' -f2) -le 50 ]
[ $status -eq 0 ] || [ $(tail -n1 error-summary.txt | cut -d' ' -f2) -le 20 ]
13 changes: 7 additions & 6 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def create(cls, session: Session, **data: Any) -> Self:
return obj

@classmethod
def create_from_object(cls, session: Session, obj: Any) -> Self:
def create_from_object(cls, session: Session, obj: Self) -> Self:
"""
Insert a new instance into the database.
Expand Down Expand Up @@ -529,7 +529,7 @@ class Award(AwardBase, ActiveRecordMixin, table=True):

# Relationships
applications: list["Application"] = Relationship(back_populates="award")
borrower: Borrower = Relationship(back_populates="awards")
borrower: Borrower | None = Relationship(back_populates="awards")

# Timestamps
created_at: datetime = Field(
Expand Down Expand Up @@ -678,9 +678,10 @@ class Application(ApplicationPrivate, ActiveRecordMixin, table=True):
borrower_documents: list["BorrowerDocument"] = Relationship(back_populates="application")
award: Award = Relationship(back_populates="applications")
borrower: Borrower = Relationship(back_populates="applications")
lender: Lender | None = Relationship(back_populates="applications")
lender: Lender = Relationship(back_populates="applications")
messages: list["Message"] = Relationship(back_populates="application")
actions: list["ApplicationAction"] = Relationship(back_populates="application")
# no back_populates, because models.CreditProduct is used as a request and response format. :issue:`376`
credit_product: CreditProduct = Relationship()

@classmethod
Expand Down Expand Up @@ -946,7 +947,7 @@ class BorrowerDocument(BorrowerDocumentBase, ActiveRecordMixin, table=True):
file: bytes

# Relationships
application: Application | None = Relationship(back_populates="borrower_documents")
application: Application = Relationship(back_populates="borrower_documents")


class Message(SQLModel, ActiveRecordMixin, table=True):
Expand All @@ -960,7 +961,7 @@ class Message(SQLModel, ActiveRecordMixin, table=True):

# Relationships
application_id: int = Field(foreign_key="application.id")
application: Application | None = Relationship(back_populates="messages")
application: Application = Relationship(back_populates="messages")
lender_id: int | None = Field(default=None, foreign_key="lender.id")

# Timestamps
Expand Down Expand Up @@ -1036,7 +1037,7 @@ class ApplicationAction(SQLModel, ActiveRecordMixin, table=True):

# Relationships
application_id: int = Field(foreign_key="application.id")
application: Application | None = Relationship(back_populates="actions")
application: Application = Relationship(back_populates="actions")
user_id: int | None = Field(default=None, foreign_key="credere_user.id")
user: User | None = Relationship(back_populates="application_actions")

Expand Down

0 comments on commit 2c50d42

Please sign in to comment.