Fix undefined Player errors by moving imports to top
- Move Player, peewee_fn, model_to_dict imports to top of file - Remove all redundant lazy imports from middle of file - All 76 unit tests pass (9 skipped cache/auth tests) - Fixes linter errors at lines 183, 188-194 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
cc6cdcc1dd
commit
408b187305
@ -6,9 +6,12 @@ Business logic for player operations with injectable dependencies.
|
||||
import logging
|
||||
from typing import List, Optional, Dict, Any, TYPE_CHECKING
|
||||
|
||||
from peewee import fn as peewee_fn
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
|
||||
from .base import BaseService
|
||||
from .interfaces import AbstractPlayerRepository, QueryResult
|
||||
from ..db_engine import Player
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .base import ServiceConfig
|
||||
@ -74,7 +77,6 @@ class PlayerService(BaseService):
|
||||
@classmethod
|
||||
def _get_real_repo(cls) -> 'RealPlayerRepository':
|
||||
"""Get a real DB repository for production use."""
|
||||
from ..db_engine import Player # Lazy import to avoid loading DB in tests
|
||||
return RealPlayerRepository(Player)
|
||||
|
||||
@classmethod
|
||||
@ -171,7 +173,6 @@ class PlayerService(BaseService):
|
||||
# Use DB-native filtering only for real Peewee models
|
||||
if first_item is not None and not isinstance(first_item, dict):
|
||||
try:
|
||||
|
||||
if team_id:
|
||||
query = query.where(Player.team_id << team_id)
|
||||
|
||||
@ -590,17 +591,14 @@ class RealPlayerRepository:
|
||||
|
||||
def update(self, data: Dict, player_id: int) -> int:
|
||||
"""Update player."""
|
||||
from ..db_engine import Player # Lazy import - only used in production
|
||||
return Player.update(**data).where(Player.id == player_id).execute()
|
||||
|
||||
def insert_many(self, data: List[Dict]) -> int:
|
||||
"""Insert multiple players."""
|
||||
from ..db_engine import Player # Lazy import - only used in production
|
||||
with Player._meta.database.atomic():
|
||||
Player.insert_many(data).execute()
|
||||
return len(data)
|
||||
|
||||
def delete_by_id(self, player_id: int) -> int:
|
||||
"""Delete player by ID."""
|
||||
from ..db_engine import Player # Lazy import - only used in production
|
||||
return Player.delete().where(Player.id == player_id).execute()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user