Problem: - Ruff removed 'from app.core.database import Base' from models/database/base.py - Import appeared "unused" (F401) but was actually a critical re-export - Caused ImportError: cannot import name 'Base' at runtime - Re-export pattern: import in one file to export from package Solution: 1. Added F401 ignore for models/database/base.py in pyproject.toml 2. Created scripts/verify_critical_imports.py verification script 3. Integrated verification into make check and CI pipeline 4. Updated documentation with explanation New Verification Script: - Checks all critical re-export imports exist - Detects import variations (parentheses, 'as' clauses) - Handles SQLAlchemy declarative_base alternatives - Runs as part of make check automatically Protected Files: - models/database/base.py - Re-exports Base for all models - models/__init__.py - Exports Base for Alembic - models/database/__init__.py - Exports Base from package - All __init__.py files (already protected) Makefile Changes: - make verify-imports - Run import verification - make check - Now includes verify-imports - make ci - Includes verify-imports in pipeline Documentation Updated: - Code quality guide explains re-export protection - Pre-commit workflow includes verification - Examples of why re-exports matter This prevents future issues where linters remove seemingly "unused" imports that are actually critical for application structure. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
# models/schema/product.py
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
from models.schema.inventory import InventoryLocationResponse
|
|
from models.schema.marketplace_product import MarketplaceProductResponse
|
|
|
|
|
|
class ProductCreate(BaseModel):
|
|
marketplace_product_id: int = Field(
|
|
..., description="MarketplaceProduct ID to add to vendor catalog"
|
|
)
|
|
product_id: str | None = Field(None, description="Vendor's internal SKU/product ID")
|
|
price: float | None = Field(None, ge=0)
|
|
sale_price: float | None = Field(None, ge=0)
|
|
currency: str | None = None
|
|
availability: str | None = None
|
|
condition: str | None = None
|
|
is_featured: bool = False
|
|
min_quantity: int = Field(1, ge=1)
|
|
max_quantity: int | None = Field(None, ge=1)
|
|
|
|
|
|
class ProductUpdate(BaseModel):
|
|
product_id: str | None = None
|
|
price: float | None = Field(None, ge=0)
|
|
sale_price: float | None = Field(None, ge=0)
|
|
currency: str | None = None
|
|
availability: str | None = None
|
|
condition: str | None = None
|
|
is_featured: bool | None = None
|
|
is_active: bool | None = None
|
|
min_quantity: int | None = Field(None, ge=1)
|
|
max_quantity: int | None = Field(None, ge=1)
|
|
|
|
|
|
class ProductResponse(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
vendor_id: int
|
|
marketplace_product: MarketplaceProductResponse
|
|
product_id: str | None
|
|
price: float | None
|
|
sale_price: float | None
|
|
currency: str | None
|
|
availability: str | None
|
|
condition: str | None
|
|
is_featured: bool
|
|
is_active: bool
|
|
display_order: int
|
|
min_quantity: int
|
|
max_quantity: int | None
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
# Include inventory summary
|
|
total_inventory: int | None = None
|
|
available_inventory: int | None = None
|
|
|
|
|
|
class ProductDetailResponse(ProductResponse):
|
|
"""Product with full inventory details."""
|
|
|
|
inventory_locations: list[InventoryLocationResponse] = []
|
|
|
|
|
|
class ProductListResponse(BaseModel):
|
|
products: list[ProductResponse]
|
|
total: int
|
|
skip: int
|
|
limit: int
|