Bart Dorsey

Python/FastAPI Backend Conflicts

Scenario A: Import Statement Conflicts

Situation: Two developers add different imports to the same file.

Example:

<<<<<<< HEAD
from fastapi import FastAPI, HTTPException
from datetime import datetime
=======
from fastapi import FastAPI, Depends
from typing import Optional
>>>>>>> feature-branch

Resolution Strategy:

  1. Keep both sets of imports if they’re all needed
  2. Remove duplicates
  3. Order imports according to PEP 8 (standard library, third-party, local)

Fixed Version:

from datetime import datetime
from typing import Optional

from fastapi import FastAPI, HTTPException, Depends

Scenario B: Endpoint Route Conflicts

Situation: Two developers add different endpoints with the same route.

Example:

<<<<<<< HEAD
@app.get("/users/{user_id}")
def get_user(user_id: int):
    return {"user_id": user_id, "name": "John"}
=======
@app.get("/users/{user_id}")
def fetch_user_details(user_id: str):
    return {"id": user_id, "username": "johndoe"}
>>>>>>> feature-branch

Resolution Strategy:

  1. Discuss with your team which implementation to keep
  2. Consider if both functionalities are needed (maybe create different endpoints)
  3. Ensure consistent data types and response formats

Scenario C: Database Model Conflicts

Situation: Multiple developers modify the same SQLAlchemy model.

Example:

class User(Base):
    __tablename__ = "users"
    
    id = Column(Integer, primary_key=True)
<<<<<<< HEAD
    email = Column(String, unique=True, nullable=False)
    created_at = Column(DateTime, default=datetime.utcnow)
=======
    username = Column(String, unique=True, nullable=False)
    is_active = Column(Boolean, default=True)
>>>>>>> feature-branch

Resolution Strategy:

  1. Usually, you’ll want to keep all fields if they serve different purposes
  2. Check for migration conflicts if using Alembic
  3. Ensure the combined model makes logical sense