Skip to content

Commit

Permalink
attempt to resolve mapper error
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 15, 2024
1 parent 7f0e0ca commit 9eb5e14
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
cache: "pip"

- name: Install dependencies
run: pip install -r requirements.txt -r requirements.dev.txt
run: pip install -r requirements.txt

- name: Run Pyright
uses: jakebailey/pyright-action@v1
Expand Down
3 changes: 0 additions & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ pre-commit
# needed for pip-compile, needed to generate requirements.txt
pip-tools
pigar

# needed to run tests
pytest==8.0.2
3 changes: 3 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
APIFlask==2.0.2
Authlib==1.2.0
boto3==1.34.83
click==8.1.7
Flask==3.0.0
Flask-Cors==4.0.0
Flask-SQLAlchemy==3.1.1
Expand All @@ -11,6 +12,8 @@ numpy==1.26.0
openai==1.17.0
pandas==2.1.1
psycopg2-binary==2.9.9
pytest==8.0.2
python-dotenv==1.0.0
redis==5.0.1
requests==2.28.1
SQLAlchemy==2.0.22
23 changes: 20 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ certifi==2024.2.2
# via
# httpcore
# httpx
# requests
cffi==1.16.0
# via cryptography
charset-normalizer==2.1.1
# via requests
click==8.1.7
# via flask
# via
# -r requirements.in
# flask
cryptography==42.0.5
# via authlib
distro==1.9.0
Expand Down Expand Up @@ -64,6 +69,9 @@ idna==3.7
# via
# anyio
# httpx
# requests
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.2
Expand Down Expand Up @@ -92,9 +100,12 @@ packaging==24.0
# via
# apispec
# marshmallow
# pytest
# webargs
pandas==2.1.1
# via -r requirements.in
pluggy==1.4.0
# via pytest
psycopg2-binary==2.9.9
# via -r requirements.in
pycparser==2.22
Expand All @@ -103,6 +114,8 @@ pydantic==2.7.0
# via openai
pydantic-core==2.18.1
# via pydantic
pytest==8.0.2
# via -r requirements.in
python-dateutil==2.9.0.post0
# via
# botocore
Expand All @@ -113,6 +126,8 @@ pytz==2024.1
# via pandas
redis==5.0.1
# via -r requirements.in
requests==2.28.1
# via -r requirements.in
s3transfer==0.10.1
# via boto3
six==1.16.0
Expand All @@ -136,8 +151,10 @@ typing-extensions==4.11.0
# sqlalchemy
tzdata==2024.1
# via pandas
urllib3==2.2.1
# via botocore
urllib3==1.26.18
# via
# botocore
# requests
webargs==8.4.0
# via apiflask
werkzeug==3.0.2
Expand Down
35 changes: 19 additions & 16 deletions server/controllers/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,20 +526,23 @@ def get_threads():
Get a list of all threads.
"""
thread_list = db.session.execute(
select(Thread).order_by(Thread.resolved, Thread.last_email.desc())
).all()
email_list = [
{
"id": thread.id,
"resolved": thread.resolved,
"emailList": [
thread_email.map()
for thread_email in db.session.execute(
select(Email).where(Email.thread_id == thread.id)
).all()
],
}
for thread in thread_list
]
thread_list = db.session.execute(select(Thread)).all()
print("thread list", thread_list)
# thread_list = db.session.execute(
# select(Thread).order_by(Thread.resolved, Thread.last_email.desc())
# ).all()
# email_list = [
# {
# "id": thread.id,
# "resolved": thread.resolved,
# "emailList": [
# thread_email.map()
# for thread_email in db.session.execute(
# select(Email).where(Email.thread_id == thread.id)
# ).all()
# ],
# }
# for thread in thread_list
# ]
email_list = []
return email_list
2 changes: 1 addition & 1 deletion server/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Document(db.Model):
response_count(int): The number of responses the document has.
"""

__tablename__ = "Documents"
__tablename__ = "document"

id: Mapped[str] = mapped_column(primary_key=True, init=False)
question: Mapped[str] = mapped_column(nullable=False)
Expand Down
8 changes: 3 additions & 5 deletions server/models/document_response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Association table for Document and Response."""

from sqlalchemy import Column, ForeignKey, Integer, Table
from sqlalchemy import Column, ForeignKey, Table

from server import db

Expand All @@ -9,14 +9,12 @@
db.Model.metadata,
Column(
"document_id",
Integer,
ForeignKey("Documents.id", ondelete="CASCADE"),
ForeignKey("document.id", ondelete="CASCADE"),
primary_key=True,
),
Column(
"response_id",
Integer,
ForeignKey("Responses.id", ondelete="CASCADE"),
ForeignKey("response.id", ondelete="CASCADE"),
primary_key=True,
),
)
4 changes: 2 additions & 2 deletions server/models/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Email(db.Model):
thread(Thread): The thread the email belongs to.
"""

__tablename__ = "Emails"
__tablename__ = "email"

id: Mapped[str] = mapped_column(primary_key=True, init=False)
date: Mapped[datetime.datetime] = mapped_column(nullable=False)
Expand All @@ -45,7 +45,7 @@ class Email(db.Model):

is_reply: Mapped[bool] = mapped_column(nullable=False)

thread_id: Mapped[str] = mapped_column(ForeignKey("Threads.id"), nullable=False)
thread_id: Mapped[str] = mapped_column(ForeignKey("thread.id"), nullable=False)
thread: Mapped["Thread"] = relationship(back_populates="emails", init=False)

def map(self):
Expand Down
4 changes: 2 additions & 2 deletions server/models/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Response(db.Model):
email(Email): The original email.
"""

__tablename__ = "Responses"
__tablename__ = "response"
__table_args__ = (UniqueConstraint("email_id", name="unique_email_id"),)

id: Mapped[str] = mapped_column(primary_key=True, init=False)
Expand All @@ -49,7 +49,7 @@ class Response(db.Model):

confidence: Mapped[float] = mapped_column(nullable=False)

email_id: Mapped[str] = mapped_column(ForeignKey("Emails.id", ondelete="CASCADE"))
email_id: Mapped[str] = mapped_column(ForeignKey("email.id", ondelete="CASCADE"))
email: Mapped["Email"] = relationship(
back_populates="response", init=False, single_parent=True
)
Expand Down
6 changes: 3 additions & 3 deletions server/models/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class Thread(db.Model):
emails(list): The emails in the thread.
"""

__tablename__ = "Threads"
__tablename__ = "thread"

id: Mapped[str] = mapped_column(primary_key=True, init=False)
last_email: Mapped[Optional[str]] = mapped_column(nullable=True, init=False)
resolved: Mapped[bool] = mapped_column(nullable=False, default=False)

emails: Mapped[List["Email"]] = relationship(
"Email",
"email",
back_populates="thread",
default_factory=list,
cascade="all, delete-orphan",
Expand All @@ -43,5 +43,5 @@ def first_sender(self):

email = db.session.execute(
select(Email).where(Email.thread_id == self.id)
).scalar_one_or_none()
).scalar()
return email.sender if email else None

0 comments on commit 9eb5e14

Please sign in to comment.