Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Backend/app/db/seed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import datetime, timezone
from db.db import AsyncSessionLocal
from models.models import User
import sys
import os
from app.db.db import AsyncSessionLocal
from app.models.models import User
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

Refactor or relocate the sys.path hack.

The runtime path append appears after the imports, so it won't help resolve them and is fragile across environments. Consider moving this line above the imports or, better, removing it entirely by structuring the project as a proper Python package (e.g., using setup.py or pyproject.toml) and running with python -m.

Apply this diff to reorder and harden path setup:

- import sys
- import os
- sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+ import sys
+ import os
+ # Ensure `app` package root is discoverable before imports
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import sys
import os
# Ensure `app` package root is discoverable before imports
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
πŸ€– Prompt for AI Agents
In Backend/app/db/seed.py at line 5, the sys.path modification occurs after
imports, making it ineffective for resolving module paths. Move the
sys.path.append line to the very top of the file before any imports to ensure it
takes effect. Alternatively, refactor the project into a proper Python package
with setup.py or pyproject.toml and run scripts using python -m to avoid needing
this path hack altogether.



async def seed_db():
Expand Down
10 changes: 5 additions & 5 deletions Backend/app/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from db.db import engine
from db.seed import seed_db
from models import models, chat
from routes.post import router as post_router
from routes.chat import router as chat_router
from app.db.db import engine
from app.db.seed import seed_db
from app.models import models, chat
from app.routes.post import router as post_router
from app.routes.chat import router as chat_router
from sqlalchemy.exc import SQLAlchemyError
import logging
import os
Expand Down
2 changes: 1 addition & 1 deletion Backend/app/models/chat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sqlalchemy import Column, String, ForeignKey, DateTime, Enum, UniqueConstraint
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from db.db import Base
from app.db.db import Base
import uuid
import enum

Expand Down
26 changes: 19 additions & 7 deletions Backend/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from sqlalchemy.orm import relationship
from datetime import datetime, timezone
from db.db import Base
from app.db.db import Base
import uuid


Expand Down Expand Up @@ -40,10 +40,18 @@ class User(Base):
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)

audience = relationship("AudienceInsights", back_populates="user", uselist=False)
sponsorships = relationship("Sponsorship", back_populates="brand")
posts = relationship("UserPost", back_populates="user")
applications = relationship("SponsorshipApplication", back_populates="creator")
audience = relationship(
"AudienceInsights", back_populates="user", uselist=False
)
sponsorships = relationship(
"Sponsorship", back_populates="brand"
)
posts = relationship(
"UserPost", back_populates="user"
)
applications = relationship(
"SponsorshipApplication", back_populates="creator"
)
payments = relationship(
"SponsorshipPayment",
foreign_keys="[SponsorshipPayment.creator_id]",
Expand Down Expand Up @@ -83,7 +91,9 @@ class Sponsorship(Base):
brand_id = Column(String, ForeignKey("users.id"), nullable=False)
title = Column(String, nullable=False)
description = Column(Text, nullable=False)
required_audience = Column(JSON) # {"age": ["18-24"], "location": ["USA", "UK"]}
required_audience = Column(
JSON
) # {"age": ["18-24"], "location": ["USA", "UK"]}
budget = Column(DECIMAL(10, 2))
engagement_minimum = Column(Float)
status = Column(String, default="open")
Expand All @@ -105,7 +115,9 @@ class UserPost(Base):
content = Column(Text, nullable=False)
post_url = Column(Text, nullable=True)
category = Column(String, nullable=True)
engagement_metrics = Column(JSON) # {"likes": 500, "comments": 100, "shares": 50}
engagement_metrics = Column(
JSON
) # {"likes": 500, "comments": 100, "shares": 50}
created_at = Column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)
Expand Down
6 changes: 4 additions & 2 deletions Backend/app/routes/post.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.future import select
from db.db import AsyncSessionLocal
from models.models import (
from app.db.db import AsyncSessionLocal
from app.models.models import (
User, AudienceInsights, Sponsorship, UserPost,
SponsorshipApplication, SponsorshipPayment, Collaboration
)
Comment on lines +4 to 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused SQLAlchemy imports.

The static analysis tools correctly identify that all the imported SQLAlchemy-related classes and AsyncSessionLocal are unused in this file. This file uses Supabase for database operations instead of SQLAlchemy ORM.

-from app.db.db import AsyncSessionLocal
-from app.models.models import (
-    User, AudienceInsights, Sponsorship, UserPost,
-    SponsorshipApplication, SponsorshipPayment, Collaboration
-)

Also remove the unused schema imports from lines 9-12:

-from schemas.schema import (
-    UserCreate, AudienceInsightsCreate, SponsorshipCreate, UserPostCreate,
-    SponsorshipApplicationCreate, SponsorshipPaymentCreate, CollaborationCreate
-)
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from app.db.db import AsyncSessionLocal
from app.models.models import (
User, AudienceInsights, Sponsorship, UserPost,
SponsorshipApplication, SponsorshipPayment, Collaboration
)
🧰 Tools
πŸͺ› Ruff (0.11.9)

4-4: app.db.db.AsyncSessionLocal imported but unused

Remove unused import: app.db.db.AsyncSessionLocal

(F401)


6-6: app.models.models.User imported but unused

Remove unused import

(F401)


6-6: app.models.models.AudienceInsights imported but unused

Remove unused import

(F401)


6-6: app.models.models.Sponsorship imported but unused

Remove unused import

(F401)


6-6: app.models.models.UserPost imported but unused

Remove unused import

(F401)


7-7: app.models.models.SponsorshipApplication imported but unused

Remove unused import

(F401)


7-7: app.models.models.SponsorshipPayment imported but unused

Remove unused import

(F401)


7-7: app.models.models.Collaboration imported but unused

Remove unused import

(F401)

πŸͺ› Flake8 (7.2.0)

[error] 4-4: 'app.db.db.AsyncSessionLocal' imported but unused

(F401)


[error] 5-5: 'app.models.models.User' imported but unused

(F401)


[error] 5-5: 'app.models.models.AudienceInsights' imported but unused

(F401)


[error] 5-5: 'app.models.models.Sponsorship' imported but unused

(F401)


[error] 5-5: 'app.models.models.UserPost' imported but unused

(F401)


[error] 5-5: 'app.models.models.SponsorshipApplication' imported but unused

(F401)


[error] 5-5: 'app.models.models.SponsorshipPayment' imported but unused

(F401)


[error] 5-5: 'app.models.models.Collaboration' imported but unused

(F401)

πŸ€– Prompt for AI Agents
In Backend/app/routes/post.py from lines 4 to 12, remove all unused imports
related to SQLAlchemy including AsyncSessionLocal and the imported models User,
AudienceInsights, Sponsorship, UserPost, SponsorshipApplication,
SponsorshipPayment, Collaboration, as well as any unused schema imports on lines
9 to 12. This cleanup is necessary because the file uses Supabase for database
operations and does not require these SQLAlchemy ORM imports.

Expand All @@ -22,6 +22,8 @@
load_dotenv()
url: str = os.getenv("SUPABASE_URL")
key: str = os.getenv("SUPABASE_KEY")
print(f"Supabase URL: {url}")
print(f"Supabase Key: {key}")
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Sensitive credentials are printed to stdout – critical leakage.

print(f"Supabase Key: {key}") exposes the service key in logs and potentially in CI output. This violates basic secret-management practice.

-print(f"Supabase URL: {url}")
-print(f"Supabase Key: {key}")
+logger = logging.getLogger(__name__)
+# Log only the fact that the env vars were loaded; never output the key itself.
+logger.info("Supabase credentials loaded from environment variables.")

Make sure the logging module is imported (it already is indirectly, but add an explicit import if needed).

πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print(f"Supabase URL: {url}")
print(f"Supabase Key: {key}")
logger = logging.getLogger(__name__)
# Log only the fact that the env vars were loaded; never output the key itself.
logger.info("Supabase credentials loaded from environment variables.")
πŸ€– Prompt for AI Agents
In Backend/app/routes/post.py around lines 25 to 26, printing the Supabase key
directly to stdout exposes sensitive credentials and risks leakage. Remove the
print statement that outputs the Supabase key. If logging the URL is necessary,
use the logging module with an appropriate log level and avoid logging the key
entirely. Also, ensure the logging module is explicitly imported at the top of
the file if not already done.

Copy link
Contributor

@Priyansh-max Priyansh-max Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eli4479 Please remove the print statements for the Supabase URL and Key. Logging sensitive information like this is not a good practice. This one is important

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

supabase: Client = create_client(url, key)

# Define Router
Expand Down
4 changes: 2 additions & 2 deletions Backend/app/services/chat_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql import select
from datetime import datetime, timezone
from models.models import User
from models.chat import ChatList, ChatMessage, MessageStatus
from app.models.models import User
from app.models.chat import ChatList, ChatMessage, MessageStatus
from typing import Dict
from redis.asyncio import Redis
import logging
Expand Down
Loading