dev: upgrade to Python 3.14 (#8521)
This commit is contained in:
1 parent
db53351731
commit
e1d0ffdc9d
77 files changed
+848
-522
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
ARG VARIANT="3.12-trixie"
|
||||
ARG VARIANT="3.14-trixie"
|
||||
FROM mcr.microsoft.com/devcontainers/python:${VARIANT}
|
||||
|
||||
# Install additional OS packages
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
"dockerfile": "Dockerfile",
|
||||
"context": "..",
|
||||
"args": {
|
||||
"VARIANT": "3.12-trixie"
|
||||
"VARIANT": "3.14-trixie"
|
||||
}
|
||||
},
|
||||
"mounts": [
|
||||
"source=mealie-devcontainer-workspace,target=/workspaces/mealie/frontend/node_modules,type=volume",
|
||||
"source=mealie-venv,target=/workspaces/mealie/.venv,type=volume",
|
||||
"source=mealie-bashhistory,target=/home/vscode/commandhistory,type=volume",
|
||||
"source=mealie-gh-config,target=/home/vscode/.config/gh,type=volume"
|
||||
],
|
||||
@@ -43,7 +44,7 @@
|
||||
51204, // used for test coverage report
|
||||
24678 // used by nuxt when hot-reloading using polling
|
||||
],
|
||||
"onCreateCommand": "task setup --force",
|
||||
"onCreateCommand": "sudo chown vscode:vscode /workspaces/mealie/.venv && task setup --force",
|
||||
"remoteUser": "vscode",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/node:2": {
|
||||
|
||||
@@ -49,7 +49,7 @@ jobs:
|
||||
- name: Set up python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.12"
|
||||
python-version: "3.14"
|
||||
|
||||
- name: Install uv
|
||||
run: pip install uv
|
||||
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.12"
|
||||
python-version: "3.14"
|
||||
|
||||
- name: Install uv
|
||||
run: pip install uv
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.12"
|
||||
python-version: "3.14"
|
||||
|
||||
- name: Set PY
|
||||
shell: bash
|
||||
|
||||
@@ -58,11 +58,17 @@ jobs:
|
||||
- name: Set up python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.12"
|
||||
python-version: "3.14"
|
||||
|
||||
- name: Install uv
|
||||
run: pip install uv
|
||||
|
||||
# Catches a lockfile resolved by an out-of-date uv, which silently ignores
|
||||
# the `exclude-newer` cooling window instead of erroring. UV_FROZEN must be
|
||||
# cleared here: for `uv lock` it means --check-exists, which conflicts with --check.
|
||||
- name: Verify lockfile matches pyproject.toml
|
||||
run: env -u UV_FROZEN uv lock --check
|
||||
|
||||
- name: Load cached venv
|
||||
id: cached-python-dependencies
|
||||
uses: actions/cache@v5
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## Project Overview
|
||||
|
||||
Mealie is a self-hosted recipe manager, meal planner, and shopping list application with a FastAPI backend (Python 3.12) and Nuxt 4 frontend (Vue 3 + TypeScript). It uses SQLAlchemy ORM with support for SQLite and PostgreSQL databases.
|
||||
Mealie is a self-hosted recipe manager, meal planner, and shopping list application with a FastAPI backend (Python 3.14) and Nuxt 4 frontend (Vue 3 + TypeScript). It uses SQLAlchemy ORM with support for SQLite and PostgreSQL databases.
|
||||
|
||||
**Development vs Production:**
|
||||
- **Development:** Frontend (port 3000) and backend (port 9000) run as separate processes
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ RUN pnpm generate
|
||||
###############################################
|
||||
# Base Image - Python
|
||||
###############################################
|
||||
FROM python:3.12-slim@sha256:7026274c107626d7e940e0e5d6730481a4600ae95d5ca7eb532dd4180313fea9 \
|
||||
FROM python:3.14-slim@sha256:caaf356f40667c496d405780745b9ac25771c189a51dfcc42430d531ea09f8a2 \
|
||||
AS python-base
|
||||
|
||||
ENV MEALIE_HOME="/app"
|
||||
|
||||
@@ -32,7 +32,7 @@ Make sure the VSCode Dev Containers extension is installed, then select "Dev Con
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- [Python 3.12](https://www.python.org/downloads/)
|
||||
- [Python 3.14](https://www.python.org/downloads/)
|
||||
- [uv](https://docs.astral.sh/uv/)
|
||||
- [Node](https://nodejs.org/en/)
|
||||
- [pnpm](https://pnpm.io/installation)
|
||||
|
||||
@@ -150,7 +150,7 @@
|
||||
```shell
|
||||
docker exec -it mealie bash
|
||||
|
||||
python /opt/mealie/lib64/python3.12/site-packages/mealie/scripts/reset_locked_users.py
|
||||
python /opt/mealie/lib64/python3.14/site-packages/mealie/scripts/reset_locked_users.py
|
||||
```
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@
|
||||
```shell
|
||||
docker exec -it mealie bash
|
||||
|
||||
python /opt/mealie/lib64/python3.12/site-packages/mealie/scripts/make_admin.py
|
||||
python /opt/mealie/lib64/python3.14/site-packages/mealie/scripts/make_admin.py
|
||||
```
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@
|
||||
```shell
|
||||
docker exec -it mealie bash
|
||||
|
||||
python /opt/mealie/lib64/python3.12/site-packages/mealie/scripts/change_password.py
|
||||
python /opt/mealie/lib64/python3.14/site-packages/mealie/scripts/change_password.py
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
```shell
|
||||
docker exec -it mealie bash
|
||||
python /opt/mealie/lib64/python3.12/site-packages/mealie/scripts/reprocess_images.py
|
||||
python /opt/mealie/lib64/python3.14/site-packages/mealie/scripts/reprocess_images.py
|
||||
```
|
||||
|
||||
### Options
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
### Example
|
||||
```shell
|
||||
python /opt/mealie/lib64/python3.12/site-packages/mealie/scripts/reprocess_images.py --workers 8
|
||||
python /opt/mealie/lib64/python3.14/site-packages/mealie/scripts/reprocess_images.py --workers 8
|
||||
```
|
||||
|
||||
## Upgrading to Mealie v1 or later
|
||||
|
||||
@@ -23,8 +23,12 @@ depends_on: str | tuple[str, ...] | None = None
|
||||
def table_exists(table, schema=None):
|
||||
config = op.get_context().config
|
||||
engine = engine_from_config(config.get_section(config.config_ini_section), prefix="sqlalchemy.")
|
||||
insp = sa.inspect(engine)
|
||||
return insp.has_table(table, schema)
|
||||
try:
|
||||
insp = sa.inspect(engine)
|
||||
return insp.has_table(table, schema)
|
||||
finally:
|
||||
# Without this the connection is only released when the engine is garbage collected.
|
||||
engine.dispose()
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ class GroupMealPlanRules(SqlAlchemyBase):
|
||||
|
||||
categories: orm.Mapped[list[Category]] = orm.relationship(Category, secondary=plan_rules_to_categories)
|
||||
tags: orm.Mapped[list[Tag]] = orm.relationship(Tag, secondary=plan_rules_to_tags)
|
||||
households: orm.Mapped[list["Household"]] = orm.relationship("Household", secondary=plan_rules_to_households)
|
||||
households: orm.Mapped[list[Household]] = orm.relationship("Household", secondary=plan_rules_to_households)
|
||||
|
||||
|
||||
def migrate_cookbooks():
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ logger = get_logger()
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan_fn(_: FastAPI) -> AsyncGenerator[None, None]:
|
||||
async def lifespan_fn(_: FastAPI) -> AsyncGenerator[None]:
|
||||
"""
|
||||
lifespan_fn controls the startup and shutdown of the FastAPI Application.
|
||||
This function is called when the FastAPI application starts and stops.
|
||||
|
||||
@@ -206,7 +206,7 @@ def validate_file_token(token: str | None = None) -> Path:
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_temporary_zip_path(auto_unlink=True) -> Generator[Path, None, None]:
|
||||
def get_temporary_zip_path(auto_unlink=True) -> Generator[Path]:
|
||||
app_dirs.TEMP_DIR.mkdir(exist_ok=True, parents=True)
|
||||
temp_path = app_dirs.TEMP_DIR / f"{uuid4().hex}.zip"
|
||||
try:
|
||||
@@ -217,7 +217,7 @@ def get_temporary_zip_path(auto_unlink=True) -> Generator[Path, None, None]:
|
||||
|
||||
|
||||
@contextmanager
|
||||
def get_temporary_path(auto_unlink=True) -> Generator[Path, None, None]:
|
||||
def get_temporary_path(auto_unlink=True) -> Generator[Path]:
|
||||
temp_path = app_dirs.TEMP_DIR.joinpath(uuid4().hex)
|
||||
temp_path.mkdir(exist_ok=True, parents=True)
|
||||
try:
|
||||
@@ -227,7 +227,7 @@ def get_temporary_path(auto_unlink=True) -> Generator[Path, None, None]:
|
||||
rmtree(temp_path)
|
||||
|
||||
|
||||
def temporary_file(ext: str = "") -> Callable[[], Generator[tempfile._TemporaryFileWrapper, None, None]]:
|
||||
def temporary_file(ext: str = "") -> Callable[[], Generator[tempfile._TemporaryFileWrapper]]:
|
||||
"""
|
||||
Returns a temporary file with the specified extension
|
||||
"""
|
||||
|
||||
@@ -136,7 +136,7 @@ class LDAPProvider(CredentialsProvider):
|
||||
|
||||
try:
|
||||
conn.simple_bind_s(settings.LDAP_QUERY_BIND, settings.LDAP_QUERY_PASSWORD)
|
||||
except (ldap.INVALID_CREDENTIALS, ldap.NO_SUCH_OBJECT):
|
||||
except ldap.INVALID_CREDENTIALS, ldap.NO_SUCH_OBJECT:
|
||||
self._logger.error("[LDAP] Unable to bind to with provided user/password")
|
||||
conn.unbind_s()
|
||||
return None
|
||||
@@ -150,7 +150,7 @@ class LDAPProvider(CredentialsProvider):
|
||||
try:
|
||||
self._logger.debug(f"[LDAP] Attempting to bind with '{user_dn}' using the provided password")
|
||||
conn.simple_bind_s(user_dn, data.password)
|
||||
except (ldap.INVALID_CREDENTIALS, ldap.NO_SUCH_OBJECT):
|
||||
except ldap.INVALID_CREDENTIALS, ldap.NO_SUCH_OBJECT:
|
||||
self._logger.error("[LDAP] Bind failed")
|
||||
conn.unbind_s()
|
||||
return None
|
||||
|
||||
@@ -26,7 +26,7 @@ class ScraperProxyMode(StrEnum):
|
||||
"""Try direct first; only retry through the proxy when a block is detected."""
|
||||
|
||||
@classmethod
|
||||
def _missing_(cls, value: object) -> "ScraperProxyMode":
|
||||
def _missing_(cls, value: object) -> ScraperProxyMode:
|
||||
# Default any unrecognized configuration value to the safest, most useful mode.
|
||||
return cls.always
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ SessionLocal, engine = sql_global_init(settings.DB_URL) # type: ignore
|
||||
|
||||
|
||||
@contextmanager
|
||||
def session_context() -> Generator[Session, None, None]:
|
||||
def session_context() -> Generator[Session]:
|
||||
"""
|
||||
session_context() provides a managed session to the database that is automatically
|
||||
closed when the context is exited. This is the preferred method of accessing the
|
||||
@@ -77,7 +77,7 @@ def session_context() -> Generator[Session, None, None]:
|
||||
sess.close()
|
||||
|
||||
|
||||
def generate_session() -> Generator[Session, None, None]:
|
||||
def generate_session() -> Generator[Session]:
|
||||
"""
|
||||
WARNING: This function should _only_ be called when used with
|
||||
using the `Depends` function from FastAPI. This function will leak
|
||||
|
||||
@@ -59,10 +59,15 @@ def db_is_at_head(alembic_cfg: config.Config) -> bool:
|
||||
raise ValueError("No database url found")
|
||||
|
||||
connectable = engine.create_engine(url)
|
||||
directory = script.ScriptDirectory.from_config(alembic_cfg)
|
||||
with connectable.begin() as connection:
|
||||
context = migration.MigrationContext.configure(connection)
|
||||
return set(context.get_current_heads()) == set(directory.get_heads())
|
||||
try:
|
||||
directory = script.ScriptDirectory.from_config(alembic_cfg)
|
||||
with connectable.begin() as connection:
|
||||
context = migration.MigrationContext.configure(connection)
|
||||
return set(context.get_current_heads()) == set(directory.get_heads())
|
||||
finally:
|
||||
# Returning from inside the `with` only returns the connection to the pool;
|
||||
# without this the underlying DBAPI connection stays open until GC.
|
||||
connectable.dispose()
|
||||
|
||||
|
||||
def safe_try(func: Callable):
|
||||
|
||||
@@ -70,7 +70,7 @@ class AIProvider(SqlAlchemyBase, BaseMixins):
|
||||
settings_id: orm.Mapped[GUID] = orm.mapped_column(
|
||||
GUID, sa.ForeignKey("ai_provider_settings.id"), nullable=False, index=True
|
||||
)
|
||||
settings: orm.Mapped["AIProviderSettings"] = orm.relationship(
|
||||
settings: orm.Mapped[AIProviderSettings] = orm.relationship(
|
||||
"AIProviderSettings", foreign_keys="[AIProvider.settings_id]", back_populates="providers"
|
||||
)
|
||||
|
||||
@@ -99,7 +99,7 @@ class AIProviderSettings(SqlAlchemyBase, BaseMixins):
|
||||
id: orm.Mapped[GUID] = orm.mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
group_id: orm.Mapped[GUID] = orm.mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: orm.Mapped["Group"] = orm.relationship("Group", back_populates="ai_provider_settings")
|
||||
group: orm.Mapped[Group] = orm.relationship("Group", back_populates="ai_provider_settings")
|
||||
providers: orm.Mapped[list[AIProvider]] = orm.relationship(
|
||||
AIProvider,
|
||||
foreign_keys="[AIProvider.settings_id]",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey, String, orm
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
@@ -15,7 +15,7 @@ class GroupDataExportsModel(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "group_data_exports"
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="data_exports", single_parent=True)
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="data_exports", single_parent=True)
|
||||
group_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("groups.id"), index=True)
|
||||
|
||||
name: Mapped[str] = mapped_column(String, nullable=False)
|
||||
|
||||
@@ -35,10 +35,10 @@ class Group(SqlAlchemyBase, BaseMixins):
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
name: FilterableColumn[str] = mapped_column(sa.String, index=True, nullable=False, unique=True)
|
||||
slug: FilterableColumn[str | None] = mapped_column(sa.String, index=True, unique=True)
|
||||
households: Mapped[list["Household"]] = orm.relationship(
|
||||
households: Mapped[list[Household]] = orm.relationship(
|
||||
"Household", back_populates="group", cascade="all, delete-orphan"
|
||||
)
|
||||
users: Mapped[list["User"]] = orm.relationship("User", back_populates="group")
|
||||
users: Mapped[list[User]] = orm.relationship("User", back_populates="group")
|
||||
categories: Mapped[list[Category]] = orm.relationship(Category, secondary=group_to_categories, single_parent=True)
|
||||
|
||||
invite_tokens: Mapped[list[GroupInviteToken]] = orm.relationship(
|
||||
@@ -62,7 +62,7 @@ class Group(SqlAlchemyBase, BaseMixins):
|
||||
)
|
||||
|
||||
# Recipes
|
||||
recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel", back_populates="group", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
@@ -79,21 +79,21 @@ class Group(SqlAlchemyBase, BaseMixins):
|
||||
GroupMealPlan, order_by="GroupMealPlan.date", **common_args
|
||||
)
|
||||
webhooks: Mapped[list[GroupWebhooksModel]] = orm.relationship(GroupWebhooksModel, **common_args)
|
||||
recipe_actions: Mapped[list["GroupRecipeAction"]] = orm.relationship("GroupRecipeAction", **common_args)
|
||||
recipe_actions: Mapped[list[GroupRecipeAction]] = orm.relationship("GroupRecipeAction", **common_args)
|
||||
cookbooks: Mapped[list[CookBook]] = orm.relationship(CookBook, **common_args)
|
||||
server_tasks: Mapped[list["ServerTaskModel"]] = orm.relationship("ServerTaskModel", **common_args)
|
||||
data_exports: Mapped[list["GroupDataExportsModel"]] = orm.relationship("GroupDataExportsModel", **common_args)
|
||||
shopping_lists: Mapped[list["ShoppingList"]] = orm.relationship("ShoppingList", **common_args)
|
||||
group_reports: Mapped[list["ReportModel"]] = orm.relationship("ReportModel", **common_args)
|
||||
group_event_notifiers: Mapped[list["GroupEventNotifierModel"]] = orm.relationship(
|
||||
server_tasks: Mapped[list[ServerTaskModel]] = orm.relationship("ServerTaskModel", **common_args)
|
||||
data_exports: Mapped[list[GroupDataExportsModel]] = orm.relationship("GroupDataExportsModel", **common_args)
|
||||
shopping_lists: Mapped[list[ShoppingList]] = orm.relationship("ShoppingList", **common_args)
|
||||
group_reports: Mapped[list[ReportModel]] = orm.relationship("ReportModel", **common_args)
|
||||
group_event_notifiers: Mapped[list[GroupEventNotifierModel]] = orm.relationship(
|
||||
"GroupEventNotifierModel", **common_args
|
||||
)
|
||||
|
||||
# Owned Models
|
||||
ingredient_units: Mapped[list["IngredientUnitModel"]] = orm.relationship("IngredientUnitModel", **common_args)
|
||||
ingredient_foods: Mapped[list["IngredientFoodModel"]] = orm.relationship("IngredientFoodModel", **common_args)
|
||||
tools: Mapped[list["Tool"]] = orm.relationship("Tool", **common_args)
|
||||
tags: Mapped[list["Tag"]] = orm.relationship("Tag", **common_args)
|
||||
ingredient_units: Mapped[list[IngredientUnitModel]] = orm.relationship("IngredientUnitModel", **common_args)
|
||||
ingredient_foods: Mapped[list[IngredientFoodModel]] = orm.relationship("IngredientFoodModel", **common_args)
|
||||
tools: Mapped[list[Tool]] = orm.relationship("Tool", **common_args)
|
||||
tags: Mapped[list[Tag]] = orm.relationship("Tag", **common_args)
|
||||
model_config = ConfigDict(
|
||||
exclude={
|
||||
"households",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
@@ -17,7 +17,7 @@ class GroupPreferencesModel(SqlAlchemyBase, BaseMixins):
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
group_id: Mapped[GUID | None] = mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="preferences")
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="preferences")
|
||||
|
||||
private_group: Mapped[bool | None] = mapped_column(sa.Boolean, default=True)
|
||||
show_announcements: Mapped[bool] = mapped_column(sa.Boolean, default=True)
|
||||
|
||||
@@ -26,7 +26,7 @@ class ReportEntryModel(SqlAlchemyBase, BaseMixins):
|
||||
timestamp: Mapped[datetime] = mapped_column(NaiveDateTime, nullable=False, default=get_utc_now)
|
||||
|
||||
report_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("group_reports.id"), nullable=False, index=True)
|
||||
report: Mapped["ReportModel"] = orm.relationship("ReportModel", back_populates="entries")
|
||||
report: Mapped[ReportModel] = orm.relationship("ReportModel", back_populates="entries")
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_) -> None:
|
||||
@@ -48,7 +48,7 @@ class ReportModel(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# Relationships
|
||||
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="group_reports", single_parent=True)
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="group_reports", single_parent=True)
|
||||
model_config = ConfigDict(exclude=["entries"])
|
||||
|
||||
@auto_init()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, Integer, String, UniqueConstraint, orm
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
@@ -25,9 +25,9 @@ class CookBook(SqlAlchemyBase, BaseMixins):
|
||||
position: FilterableColumn[int] = mapped_column(Integer, nullable=False, default=1)
|
||||
|
||||
group_id: FilterableColumn[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"), index=True)
|
||||
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="cookbooks")
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="cookbooks")
|
||||
household_id: FilterableColumn[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("households.id"), index=True)
|
||||
household: Mapped[Optional["Household"]] = orm.relationship("Household", back_populates="cookbooks")
|
||||
household: Mapped[Household | None] = orm.relationship("Household", back_populates="cookbooks")
|
||||
|
||||
name: FilterableColumn[str] = mapped_column(String, nullable=False)
|
||||
slug: FilterableColumn[str] = mapped_column(String, nullable=False, index=True)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, String, orm
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
@@ -65,11 +65,9 @@ class GroupEventNotifierModel(SqlAlchemyBase, BaseMixins):
|
||||
enabled: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
||||
apprise_url: Mapped[str] = mapped_column(String, nullable=False)
|
||||
|
||||
group: Mapped[Optional["Group"]] = orm.relationship(
|
||||
"Group", back_populates="group_event_notifiers", single_parent=True
|
||||
)
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="group_event_notifiers", single_parent=True)
|
||||
group_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("groups.id"), index=True)
|
||||
household: Mapped[Optional["Household"]] = orm.relationship(
|
||||
household: Mapped[Household | None] = orm.relationship(
|
||||
"Household", back_populates="group_event_notifiers", single_parent=True
|
||||
)
|
||||
household_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("households.id"), index=True)
|
||||
|
||||
@@ -37,10 +37,10 @@ class Household(SqlAlchemyBase, BaseMixins):
|
||||
name: FilterableColumn[str] = mapped_column(sa.String, index=True, nullable=False)
|
||||
slug: FilterableColumn[str | None] = mapped_column(sa.String, index=True)
|
||||
|
||||
invite_tokens: Mapped[list["GroupInviteToken"]] = orm.relationship(
|
||||
invite_tokens: Mapped[list[GroupInviteToken]] = orm.relationship(
|
||||
"GroupInviteToken", back_populates="household", cascade="all, delete-orphan"
|
||||
)
|
||||
preferences: Mapped["HouseholdPreferencesModel"] = orm.relationship(
|
||||
preferences: Mapped[HouseholdPreferencesModel] = orm.relationship(
|
||||
"HouseholdPreferencesModel",
|
||||
back_populates="household",
|
||||
uselist=False,
|
||||
@@ -49,8 +49,8 @@ class Household(SqlAlchemyBase, BaseMixins):
|
||||
)
|
||||
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="households")
|
||||
users: Mapped[list["User"]] = orm.relationship("User", back_populates="household")
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="households")
|
||||
users: Mapped[list[User]] = orm.relationship("User", back_populates="household")
|
||||
|
||||
COMMON_ARGS = {
|
||||
"back_populates": "household",
|
||||
@@ -58,23 +58,23 @@ class Household(SqlAlchemyBase, BaseMixins):
|
||||
"single_parent": True,
|
||||
}
|
||||
|
||||
recipe_actions: Mapped[list["GroupRecipeAction"]] = orm.relationship("GroupRecipeAction", **COMMON_ARGS)
|
||||
cookbooks: Mapped[list["CookBook"]] = orm.relationship("CookBook", **COMMON_ARGS)
|
||||
recipe_actions: Mapped[list[GroupRecipeAction]] = orm.relationship("GroupRecipeAction", **COMMON_ARGS)
|
||||
cookbooks: Mapped[list[CookBook]] = orm.relationship("CookBook", **COMMON_ARGS)
|
||||
|
||||
webhooks: Mapped[list["GroupWebhooksModel"]] = orm.relationship("GroupWebhooksModel", **COMMON_ARGS)
|
||||
group_event_notifiers: Mapped[list["GroupEventNotifierModel"]] = orm.relationship(
|
||||
webhooks: Mapped[list[GroupWebhooksModel]] = orm.relationship("GroupWebhooksModel", **COMMON_ARGS)
|
||||
group_event_notifiers: Mapped[list[GroupEventNotifierModel]] = orm.relationship(
|
||||
"GroupEventNotifierModel", **COMMON_ARGS
|
||||
)
|
||||
|
||||
made_recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
made_recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel", secondary=HouseholdToRecipe.__tablename__, back_populates="made_by"
|
||||
)
|
||||
ingredient_foods_on_hand: Mapped[list["IngredientFoodModel"]] = orm.relationship(
|
||||
ingredient_foods_on_hand: Mapped[list[IngredientFoodModel]] = orm.relationship(
|
||||
"IngredientFoodModel",
|
||||
secondary=households_to_ingredient_foods,
|
||||
back_populates="households_with_ingredient_food",
|
||||
)
|
||||
tools_on_hand: Mapped[list["Tool"]] = orm.relationship(
|
||||
tools_on_hand: Mapped[list[Tool]] = orm.relationship(
|
||||
"Tool", secondary=households_to_tools, back_populates="households_with_tool"
|
||||
)
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ class HouseholdToRecipe(SqlAlchemyBase, BaseMixins):
|
||||
__table_args__ = (UniqueConstraint("household_id", "recipe_id", name="household_id_recipe_id_key"),)
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
household: Mapped["Household"] = relationship("Household", viewonly=True)
|
||||
household: Mapped[Household] = relationship("Household", viewonly=True)
|
||||
household_id = Column(GUID, ForeignKey("households.id"), index=True, primary_key=True)
|
||||
recipe: Mapped["RecipeModel"] = relationship("RecipeModel", viewonly=True)
|
||||
recipe: Mapped[RecipeModel] = relationship("RecipeModel", viewonly=True)
|
||||
recipe_id = Column(GUID, ForeignKey("recipes.id"), index=True, primary_key=True)
|
||||
group_id: AssociationProxy[GUID] = association_proxy("household", "group_id")
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey, Integer, String, orm
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
@@ -18,9 +18,9 @@ class GroupInviteToken(SqlAlchemyBase, BaseMixins):
|
||||
uses_left: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
|
||||
|
||||
group_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("groups.id"), index=True)
|
||||
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="invite_tokens")
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="invite_tokens")
|
||||
household_id: Mapped[guid.GUID | None] = mapped_column(guid.GUID, ForeignKey("households.id"), index=True)
|
||||
household: Mapped[Optional["Household"]] = orm.relationship("Household", back_populates="invite_tokens")
|
||||
household: Mapped[Household | None] = orm.relationship("Household", back_populates="invite_tokens")
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Column, Date, ForeignKey, String, Table, UniqueConstraint, orm
|
||||
from sqlalchemy.ext.associationproxy import AssociationProxy, association_proxy
|
||||
@@ -45,7 +45,7 @@ class GroupMealPlanRules(BaseMixins, SqlAlchemyBase):
|
||||
# Old filters - deprecated in favor of query filter strings
|
||||
categories: Mapped[list[Category]] = orm.relationship(Category, secondary=plan_rules_to_categories)
|
||||
tags: Mapped[list[Tag]] = orm.relationship(Tag, secondary=plan_rules_to_tags)
|
||||
households: Mapped[list["Household"]] = orm.relationship("Household", secondary=plan_rules_to_households)
|
||||
households: Mapped[list[Household]] = orm.relationship("Household", secondary=plan_rules_to_households)
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_) -> None:
|
||||
@@ -61,16 +61,14 @@ class GroupMealPlan(SqlAlchemyBase, BaseMixins):
|
||||
text: FilterableColumn[str] = mapped_column(String, nullable=False)
|
||||
|
||||
group_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("groups.id"), index=True)
|
||||
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="mealplans")
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="mealplans")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("user", "household_id")
|
||||
household: AssociationProxy["Household"] = association_proxy("user", "household")
|
||||
household: AssociationProxy[Household] = association_proxy("user", "household")
|
||||
user_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("users.id"), index=True)
|
||||
user: Mapped[Optional["User"]] = orm.relationship("User", back_populates="mealplans")
|
||||
user: Mapped[User | None] = orm.relationship("User", back_populates="mealplans")
|
||||
|
||||
recipe_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"), index=True)
|
||||
recipe: Mapped[Optional["RecipeModel"]] = orm.relationship(
|
||||
"RecipeModel", back_populates="meal_entries", uselist=False
|
||||
)
|
||||
recipe: Mapped[RecipeModel | None] = orm.relationship("RecipeModel", back_populates="meal_entries", uselist=False)
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_) -> None:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm as orm
|
||||
@@ -20,7 +20,7 @@ class HouseholdPreferencesModel(SqlAlchemyBase, BaseMixins):
|
||||
household_id: FilterableColumn[GUID | None] = mapped_column(
|
||||
GUID, sa.ForeignKey("households.id"), nullable=False, index=True
|
||||
)
|
||||
household: Mapped[Optional["Household"]] = orm.relationship("Household", back_populates="preferences")
|
||||
household: Mapped[Household | None] = orm.relationship("Household", back_populates="preferences")
|
||||
group_id: AssociationProxy[GUID] = association_proxy("household", "group_id")
|
||||
|
||||
private_household: FilterableColumn[bool | None] = mapped_column(sa.Boolean, default=True)
|
||||
|
||||
@@ -16,9 +16,9 @@ class GroupRecipeAction(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "recipe_actions"
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), index=True)
|
||||
group: Mapped["Group"] = relationship("Group", back_populates="recipe_actions", single_parent=True)
|
||||
group: Mapped[Group] = relationship("Group", back_populates="recipe_actions", single_parent=True)
|
||||
household_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("households.id"), index=True)
|
||||
household: Mapped["Household"] = relationship("Household", back_populates="recipe_actions")
|
||||
household: Mapped[Household] = relationship("Household", back_populates="recipe_actions")
|
||||
|
||||
action_type: FilterableColumn[str] = mapped_column(String, index=True)
|
||||
title: FilterableColumn[str] = mapped_column(String, index=True)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from contextvars import ContextVar
|
||||
from datetime import UTC, datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pydantic import ConfigDict
|
||||
from sqlalchemy import Boolean, Float, ForeignKey, Integer, String, UniqueConstraint, event, orm
|
||||
@@ -27,7 +27,7 @@ class ShoppingListItemRecipeReference(BaseMixins, SqlAlchemyBase):
|
||||
__tablename__ = "shopping_list_item_recipe_reference"
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
shopping_list_item: Mapped["ShoppingListItem"] = orm.relationship(
|
||||
shopping_list_item: Mapped[ShoppingListItem] = orm.relationship(
|
||||
"ShoppingListItem", back_populates="recipe_references"
|
||||
)
|
||||
shopping_list_item_id: FilterableColumn[GUID] = mapped_column(
|
||||
@@ -35,7 +35,7 @@ class ShoppingListItemRecipeReference(BaseMixins, SqlAlchemyBase):
|
||||
)
|
||||
|
||||
recipe_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"), index=True)
|
||||
recipe: Mapped[Optional["RecipeModel"]] = orm.relationship("RecipeModel", back_populates="shopping_list_item_refs")
|
||||
recipe: Mapped[RecipeModel | None] = orm.relationship("RecipeModel", back_populates="shopping_list_item_refs")
|
||||
recipe_quantity: FilterableColumn[float] = mapped_column(Float, nullable=False)
|
||||
recipe_scale: FilterableColumn[float] = mapped_column(Float, default=1)
|
||||
recipe_note: FilterableColumn[str | None] = mapped_column(String)
|
||||
@@ -53,7 +53,7 @@ class ShoppingListItem(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# Id's
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
shopping_list: Mapped["ShoppingList"] = orm.relationship("ShoppingList", back_populates="list_items")
|
||||
shopping_list: Mapped[ShoppingList] = orm.relationship("ShoppingList", back_populates="list_items")
|
||||
shopping_list_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("shopping_lists.id"), index=True)
|
||||
|
||||
group_id: AssociationProxy[GUID] = association_proxy("shopping_list", "group_id")
|
||||
@@ -102,13 +102,13 @@ class ShoppingListRecipeReference(BaseMixins, SqlAlchemyBase):
|
||||
__tablename__ = "shopping_list_recipe_reference"
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
shopping_list: Mapped["ShoppingList"] = orm.relationship("ShoppingList", back_populates="recipe_references")
|
||||
shopping_list: Mapped[ShoppingList] = orm.relationship("ShoppingList", back_populates="recipe_references")
|
||||
shopping_list_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("shopping_lists.id"), primary_key=True)
|
||||
group_id: AssociationProxy[GUID] = association_proxy("shopping_list", "group_id")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("shopping_list", "household_id")
|
||||
|
||||
recipe_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"), index=True)
|
||||
recipe: Mapped[Optional["RecipeModel"]] = orm.relationship(
|
||||
recipe: Mapped[RecipeModel | None] = orm.relationship(
|
||||
"RecipeModel", uselist=False, back_populates="shopping_list_refs"
|
||||
)
|
||||
|
||||
@@ -126,10 +126,10 @@ class ShoppingListMultiPurposeLabel(SqlAlchemyBase, BaseMixins):
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
shopping_list_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("shopping_lists.id"), primary_key=True)
|
||||
shopping_list: Mapped["ShoppingList"] = orm.relationship("ShoppingList", back_populates="label_settings")
|
||||
shopping_list: Mapped[ShoppingList] = orm.relationship("ShoppingList", back_populates="label_settings")
|
||||
|
||||
label_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("multi_purpose_labels.id"), primary_key=True)
|
||||
label: Mapped["MultiPurposeLabel"] = orm.relationship(
|
||||
label: Mapped[MultiPurposeLabel] = orm.relationship(
|
||||
"MultiPurposeLabel", back_populates="shopping_lists_label_settings"
|
||||
)
|
||||
|
||||
@@ -149,11 +149,11 @@ class ShoppingList(SqlAlchemyBase, BaseMixins):
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="shopping_lists")
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="shopping_lists")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("user", "household_id")
|
||||
household: AssociationProxy["Household"] = association_proxy("user", "household")
|
||||
household: AssociationProxy[Household] = association_proxy("user", "household")
|
||||
user_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user: Mapped["User"] = orm.relationship("User", back_populates="shopping_lists")
|
||||
user: Mapped[User] = orm.relationship("User", back_populates="shopping_lists")
|
||||
|
||||
name: FilterableColumn[str | None] = mapped_column(String)
|
||||
list_items: Mapped[list[ShoppingListItem]] = orm.relationship(
|
||||
@@ -166,7 +166,7 @@ class ShoppingList(SqlAlchemyBase, BaseMixins):
|
||||
recipe_references: Mapped[list[ShoppingListRecipeReference]] = orm.relationship(
|
||||
ShoppingListRecipeReference, cascade="all, delete, delete-orphan"
|
||||
)
|
||||
label_settings: Mapped[list["ShoppingListMultiPurposeLabel"]] = orm.relationship(
|
||||
label_settings: Mapped[list[ShoppingListMultiPurposeLabel]] = orm.relationship(
|
||||
ShoppingListMultiPurposeLabel,
|
||||
cascade="all, delete, delete-orphan",
|
||||
order_by="ShoppingListMultiPurposeLabel.position",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import UTC, datetime, time
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Boolean, ForeignKey, String, Time, orm
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
@@ -17,11 +17,9 @@ class GroupWebhooksModel(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "webhook_urls"
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
group: Mapped[Optional["Group"]] = orm.relationship("Group", back_populates="webhooks", single_parent=True)
|
||||
group: Mapped[Group | None] = orm.relationship("Group", back_populates="webhooks", single_parent=True)
|
||||
group_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("groups.id"), index=True)
|
||||
household: Mapped[Optional["Household"]] = orm.relationship(
|
||||
"Household", back_populates="webhooks", single_parent=True
|
||||
)
|
||||
household: Mapped[Household | None] = orm.relationship("Household", back_populates="webhooks", single_parent=True)
|
||||
household_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("households.id"), index=True)
|
||||
|
||||
enabled: Mapped[bool | None] = mapped_column(Boolean, default=False)
|
||||
|
||||
@@ -56,13 +56,13 @@ class Category(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# ID Relationships
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="categories", foreign_keys=[group_id])
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="categories", foreign_keys=[group_id])
|
||||
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
name: FilterableColumn[str] = mapped_column(sa.String, index=True, nullable=False)
|
||||
slug: FilterableColumn[str] = mapped_column(sa.String, index=True, nullable=False)
|
||||
recipe_count: Mapped[int] = query_expression(default_expr=literal(0))
|
||||
recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel", secondary=recipes_to_categories, back_populates="recipe_category"
|
||||
)
|
||||
|
||||
|
||||
@@ -20,16 +20,14 @@ class RecipeComment(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# Recipe Link
|
||||
recipe_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("recipes.id"), nullable=False, index=True)
|
||||
recipe: Mapped["RecipeModel"] = orm.relationship("RecipeModel", back_populates="comments")
|
||||
recipe: Mapped[RecipeModel] = orm.relationship("RecipeModel", back_populates="comments")
|
||||
|
||||
group_id: AssociationProxy[GUID] = association_proxy("recipe", "group_id")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("recipe", "household_id")
|
||||
|
||||
# User Link
|
||||
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user: Mapped["User"] = orm.relationship(
|
||||
"User", back_populates="comments", single_parent=True, foreign_keys=[user_id]
|
||||
)
|
||||
user: Mapped[User] = orm.relationship("User", back_populates="comments", single_parent=True, foreign_keys=[user_id])
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_) -> None:
|
||||
|
||||
@@ -94,7 +94,7 @@ class IngredientUnitModel(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# ID Relationships
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="ingredient_units", foreign_keys=[group_id])
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="ingredient_units", foreign_keys=[group_id])
|
||||
|
||||
name: FilterableColumn[str | None] = mapped_column(String)
|
||||
plural_name: FilterableColumn[str | None] = mapped_column(String)
|
||||
@@ -104,10 +104,8 @@ class IngredientUnitModel(SqlAlchemyBase, BaseMixins):
|
||||
use_abbreviation: FilterableColumn[bool | None] = mapped_column(Boolean, default=False)
|
||||
fraction: FilterableColumn[bool | None] = mapped_column(Boolean, default=True)
|
||||
|
||||
ingredients: Mapped[list["RecipeIngredientModel"]] = orm.relationship(
|
||||
"RecipeIngredientModel", back_populates="unit"
|
||||
)
|
||||
aliases: Mapped[list["IngredientUnitAliasModel"]] = orm.relationship(
|
||||
ingredients: Mapped[list[RecipeIngredientModel]] = orm.relationship("RecipeIngredientModel", back_populates="unit")
|
||||
aliases: Mapped[list[IngredientUnitAliasModel]] = orm.relationship(
|
||||
"IngredientUnitAliasModel",
|
||||
back_populates="unit",
|
||||
cascade="all, delete, delete-orphan",
|
||||
@@ -217,8 +215,8 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# ID Relationships
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="ingredient_foods", foreign_keys=[group_id])
|
||||
households_with_ingredient_food: Mapped[list["Household"]] = orm.relationship(
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="ingredient_foods", foreign_keys=[group_id])
|
||||
households_with_ingredient_food: Mapped[list[Household]] = orm.relationship(
|
||||
"Household", secondary=households_to_ingredient_foods, back_populates="ingredient_foods_on_hand"
|
||||
)
|
||||
|
||||
@@ -226,16 +224,14 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
|
||||
plural_name: FilterableColumn[str | None] = mapped_column(String)
|
||||
description: FilterableColumn[str | None] = mapped_column(String)
|
||||
|
||||
ingredients: Mapped[list["RecipeIngredientModel"]] = orm.relationship(
|
||||
"RecipeIngredientModel", back_populates="food"
|
||||
)
|
||||
aliases: Mapped[list["IngredientFoodAliasModel"]] = orm.relationship(
|
||||
ingredients: Mapped[list[RecipeIngredientModel]] = orm.relationship("RecipeIngredientModel", back_populates="food")
|
||||
aliases: Mapped[list[IngredientFoodAliasModel]] = orm.relationship(
|
||||
"IngredientFoodAliasModel",
|
||||
back_populates="food",
|
||||
cascade="all, delete, delete-orphan",
|
||||
)
|
||||
# substitutions this food offers, e.g. chicken stock -> chicken broth
|
||||
substitutions: Mapped[list["IngredientFoodSubstitutionModel"]] = orm.relationship(
|
||||
substitutions: Mapped[list[IngredientFoodSubstitutionModel]] = orm.relationship(
|
||||
"IngredientFoodSubstitutionModel",
|
||||
back_populates="food",
|
||||
foreign_keys="IngredientFoodSubstitutionModel.food_id",
|
||||
@@ -244,7 +240,7 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
|
||||
collection_class=ordering_list("position"),
|
||||
)
|
||||
# substitutions pointing at this food; exists so deleting a food cleans up the ones aimed at it
|
||||
substitution_references: Mapped[list["IngredientFoodSubstitutionModel"]] = orm.relationship(
|
||||
substitution_references: Mapped[list[IngredientFoodSubstitutionModel]] = orm.relationship(
|
||||
"IngredientFoodSubstitutionModel",
|
||||
back_populates="substitute_food",
|
||||
foreign_keys="IngredientFoodSubstitutionModel.substitute_food_id",
|
||||
@@ -253,7 +249,7 @@ class IngredientFoodModel(SqlAlchemyBase, BaseMixins):
|
||||
# the same, for the recipe tier: without it a deleted food leaves ingredient substitutions
|
||||
# pointing at a row that is gone, which renders as an empty popover on SQLite and fails the
|
||||
# foreign key outright on Postgres
|
||||
recipe_substitution_references: Mapped[list["RecipeIngredientSubstitutionModel"]] = orm.relationship(
|
||||
recipe_substitution_references: Mapped[list[RecipeIngredientSubstitutionModel]] = orm.relationship(
|
||||
"RecipeIngredientSubstitutionModel",
|
||||
back_populates="substitute_food",
|
||||
cascade="all, delete, delete-orphan",
|
||||
@@ -389,7 +385,7 @@ class IngredientUnitAliasModel(SqlAlchemyBase, BaseMixins):
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
unit_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("ingredient_units.id"), primary_key=True)
|
||||
unit: Mapped["IngredientUnitModel"] = orm.relationship("IngredientUnitModel", back_populates="aliases")
|
||||
unit: Mapped[IngredientUnitModel] = orm.relationship("IngredientUnitModel", back_populates="aliases")
|
||||
|
||||
name: FilterableColumn[str] = mapped_column(String)
|
||||
|
||||
@@ -430,7 +426,7 @@ class IngredientFoodAliasModel(SqlAlchemyBase, BaseMixins):
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
food_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("ingredient_foods.id"), primary_key=True)
|
||||
food: Mapped["IngredientFoodModel"] = orm.relationship("IngredientFoodModel", back_populates="aliases")
|
||||
food: Mapped[IngredientFoodModel] = orm.relationship("IngredientFoodModel", back_populates="aliases")
|
||||
|
||||
name: FilterableColumn[str] = mapped_column(String)
|
||||
|
||||
@@ -488,14 +484,14 @@ class IngredientFoodSubstitutionModel(SqlAlchemyBase, BaseMixins):
|
||||
id: FilterableColumn[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
food_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("ingredient_foods.id"), index=True, nullable=False)
|
||||
food: Mapped["IngredientFoodModel"] = orm.relationship(
|
||||
food: Mapped[IngredientFoodModel] = orm.relationship(
|
||||
"IngredientFoodModel", back_populates="substitutions", foreign_keys=[food_id]
|
||||
)
|
||||
|
||||
substitute_food_id: FilterableColumn[GUID | None] = mapped_column(
|
||||
GUID, ForeignKey("ingredient_foods.id"), index=True
|
||||
)
|
||||
substitute_food: Mapped["IngredientFoodModel | None"] = orm.relationship(
|
||||
substitute_food: Mapped[IngredientFoodModel | None] = orm.relationship(
|
||||
"IngredientFoodModel", back_populates="substitution_references", foreign_keys=[substitute_food_id]
|
||||
)
|
||||
|
||||
@@ -528,11 +524,11 @@ class RecipeIngredientModel(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# Recipe Reference
|
||||
referenced_recipe_id: FilterableColumn[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"), index=True)
|
||||
referenced_recipe: Mapped["RecipeModel"] = orm.relationship(
|
||||
referenced_recipe: Mapped[RecipeModel] = orm.relationship(
|
||||
"RecipeModel", back_populates="referenced_ingredients", foreign_keys=[referenced_recipe_id]
|
||||
)
|
||||
|
||||
substitutions: Mapped[list["RecipeIngredientSubstitutionModel"]] = orm.relationship(
|
||||
substitutions: Mapped[list[RecipeIngredientSubstitutionModel]] = orm.relationship(
|
||||
"RecipeIngredientSubstitutionModel",
|
||||
back_populates="ingredient",
|
||||
cascade="all, delete, delete-orphan",
|
||||
@@ -649,14 +645,14 @@ class RecipeIngredientSubstitutionModel(SqlAlchemyBase, BaseMixins):
|
||||
ingredient_id: FilterableColumn[int] = mapped_column(
|
||||
Integer, ForeignKey("recipes_ingredients.id"), index=True, nullable=False
|
||||
)
|
||||
ingredient: Mapped["RecipeIngredientModel"] = orm.relationship(
|
||||
ingredient: Mapped[RecipeIngredientModel] = orm.relationship(
|
||||
"RecipeIngredientModel", back_populates="substitutions"
|
||||
)
|
||||
|
||||
substitute_food_id: FilterableColumn[GUID | None] = mapped_column(
|
||||
GUID, ForeignKey("ingredient_foods.id"), index=True
|
||||
)
|
||||
substitute_food: Mapped["IngredientFoodModel | None"] = orm.relationship(
|
||||
substitute_food: Mapped[IngredientFoodModel | None] = orm.relationship(
|
||||
"IngredientFoodModel", back_populates="recipe_substitution_references"
|
||||
)
|
||||
|
||||
|
||||
@@ -23,11 +23,11 @@ class MultiPurposeLabel(SqlAlchemyBase, BaseMixins):
|
||||
color: FilterableColumn[str] = mapped_column(String(10), nullable=False, default="")
|
||||
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="labels")
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="labels")
|
||||
|
||||
shopping_list_items: Mapped[list["ShoppingListItem"]] = orm.relationship("ShoppingListItem", back_populates="label")
|
||||
foods: Mapped[list["IngredientFoodModel"]] = orm.relationship("IngredientFoodModel", back_populates="label")
|
||||
shopping_lists_label_settings: Mapped[list["ShoppingListMultiPurposeLabel"]] = orm.relationship(
|
||||
shopping_list_items: Mapped[list[ShoppingListItem]] = orm.relationship("ShoppingListItem", back_populates="label")
|
||||
foods: Mapped[list[IngredientFoodModel]] = orm.relationship("IngredientFoodModel", back_populates="label")
|
||||
shopping_lists_label_settings: Mapped[list[ShoppingListMultiPurposeLabel]] = orm.relationship(
|
||||
"ShoppingListMultiPurposeLabel", back_populates="label", cascade="all, delete, delete-orphan"
|
||||
)
|
||||
|
||||
|
||||
@@ -50,22 +50,22 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# ID Relationships
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="recipes", foreign_keys=[group_id])
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="recipes", foreign_keys=[group_id])
|
||||
|
||||
household_id: AssociationProxy[GUID] = association_proxy("user", "household_id")
|
||||
household: AssociationProxy["Household"] = association_proxy("user", "household")
|
||||
household: AssociationProxy[Household] = association_proxy("user", "household")
|
||||
|
||||
user_id: FilterableColumn[GUID | None] = mapped_column(GUID, sa.ForeignKey("users.id", use_alter=True), index=True)
|
||||
user: Mapped["User"] = orm.relationship("User", uselist=False, foreign_keys=[user_id])
|
||||
user: Mapped[User] = orm.relationship("User", uselist=False, foreign_keys=[user_id])
|
||||
|
||||
rating: FilterableColumn[float | None] = mapped_column(sa.Float, index=True, nullable=True)
|
||||
rated_by: Mapped[list["User"]] = orm.relationship(
|
||||
rated_by: Mapped[list[User]] = orm.relationship(
|
||||
"User",
|
||||
secondary=UserToRecipe.__tablename__,
|
||||
back_populates="rated_recipes",
|
||||
overlaps="recipe,favorited_by,favorited_recipes",
|
||||
)
|
||||
favorited_by: Mapped[list["User"]] = orm.relationship(
|
||||
favorited_by: Mapped[list[User]] = orm.relationship(
|
||||
"User",
|
||||
secondary=UserToRecipe.__tablename__,
|
||||
primaryjoin="and_(RecipeModel.id==UserToRecipe.recipe_id, UserToRecipe.is_favorite==True)",
|
||||
@@ -73,7 +73,7 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
overlaps="recipe,rated_by,rated_recipes",
|
||||
)
|
||||
|
||||
meal_entries: Mapped[list["GroupMealPlan"]] = orm.relationship(
|
||||
meal_entries: Mapped[list[GroupMealPlan]] = orm.relationship(
|
||||
"GroupMealPlan", back_populates="recipe", cascade="all, delete-orphan"
|
||||
)
|
||||
|
||||
@@ -95,19 +95,19 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
assets: Mapped[list[RecipeAsset]] = orm.relationship("RecipeAsset", cascade="all, delete-orphan")
|
||||
nutrition: Mapped[Nutrition] = orm.relationship("Nutrition", uselist=False, cascade="all, delete-orphan")
|
||||
recipe_category: Mapped[list["Category"]] = orm.relationship(
|
||||
recipe_category: Mapped[list[Category]] = orm.relationship(
|
||||
"Category", secondary=recipes_to_categories, back_populates="recipes"
|
||||
)
|
||||
tools: Mapped[list["Tool"]] = orm.relationship("Tool", secondary=recipes_to_tools, back_populates="recipes")
|
||||
tools: Mapped[list[Tool]] = orm.relationship("Tool", secondary=recipes_to_tools, back_populates="recipes")
|
||||
|
||||
recipe_ingredient: Mapped[list["RecipeIngredientModel"]] = orm.relationship(
|
||||
recipe_ingredient: Mapped[list[RecipeIngredientModel]] = orm.relationship(
|
||||
"RecipeIngredientModel",
|
||||
cascade="all, delete-orphan",
|
||||
order_by="RecipeIngredientModel.position",
|
||||
collection_class=ordering_list("position"),
|
||||
foreign_keys="RecipeIngredientModel.recipe_id",
|
||||
)
|
||||
referenced_ingredients: Mapped[list["RecipeIngredientModel"]] = orm.relationship(
|
||||
referenced_ingredients: Mapped[list[RecipeIngredientModel]] = orm.relationship(
|
||||
"RecipeIngredientModel",
|
||||
foreign_keys="RecipeIngredientModel.referenced_recipe_id",
|
||||
back_populates="referenced_recipe",
|
||||
@@ -132,10 +132,10 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
)
|
||||
|
||||
# Mealie Specific
|
||||
settings: Mapped[list["RecipeSettings"]] = orm.relationship(
|
||||
settings: Mapped[list[RecipeSettings]] = orm.relationship(
|
||||
"RecipeSettings", uselist=False, cascade="all, delete-orphan"
|
||||
)
|
||||
tags: Mapped[list["Tag"]] = orm.relationship("Tag", secondary=recipes_to_tags, back_populates="recipes")
|
||||
tags: Mapped[list[Tag]] = orm.relationship("Tag", secondary=recipes_to_tags, back_populates="recipes")
|
||||
notes: Mapped[list[Note]] = orm.relationship("Note", cascade="all, delete-orphan")
|
||||
org_url: FilterableColumn[str | None] = mapped_column(sa.String)
|
||||
extras: Mapped[list[ApiExtras]] = orm.relationship("ApiExtras", cascade="all, delete-orphan")
|
||||
@@ -145,17 +145,17 @@ class RecipeModel(SqlAlchemyBase, BaseMixins):
|
||||
date_updated: FilterableColumn[datetime | None] = mapped_column(NaiveDateTime)
|
||||
|
||||
last_made: FilterableColumn[datetime | None] = mapped_column(NaiveDateTime)
|
||||
made_by: Mapped[list["Household"]] = orm.relationship(
|
||||
made_by: Mapped[list[Household]] = orm.relationship(
|
||||
"Household", secondary=HouseholdToRecipe.__tablename__, back_populates="made_recipes"
|
||||
)
|
||||
|
||||
# Shopping List Refs
|
||||
shopping_list_refs: Mapped[list["ShoppingListRecipeReference"]] = orm.relationship(
|
||||
shopping_list_refs: Mapped[list[ShoppingListRecipeReference]] = orm.relationship(
|
||||
"ShoppingListRecipeReference",
|
||||
back_populates="recipe",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
shopping_list_item_refs: Mapped[list["ShoppingListItemRecipeReference"]] = orm.relationship(
|
||||
shopping_list_item_refs: Mapped[list[ShoppingListItemRecipeReference]] = orm.relationship(
|
||||
"ShoppingListItemRecipeReference",
|
||||
back_populates="recipe",
|
||||
cascade="all, delete-orphan",
|
||||
|
||||
@@ -22,14 +22,14 @@ class RecipeTimelineEvent(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# Parent Recipe
|
||||
recipe_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("recipes.id"), nullable=False, index=True)
|
||||
recipe: Mapped["RecipeModel"] = relationship("RecipeModel", back_populates="timeline_events")
|
||||
recipe: Mapped[RecipeModel] = relationship("RecipeModel", back_populates="timeline_events")
|
||||
|
||||
group_id: AssociationProxy[GUID] = association_proxy("recipe", "group_id")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("recipe", "household_id")
|
||||
|
||||
# Related User (Actor)
|
||||
user_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user: Mapped["User"] = relationship(
|
||||
user: Mapped[User] = relationship(
|
||||
"User", back_populates="recipe_timeline_events", single_parent=True, foreign_keys=[user_id]
|
||||
)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class RecipeShareTokenModel(SqlAlchemyBase, BaseMixins):
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, sa.ForeignKey("groups.id"), nullable=False, index=True)
|
||||
|
||||
recipe_id: FilterableColumn[GUID] = mapped_column(GUID, sa.ForeignKey("recipes.id"), nullable=False, index=True)
|
||||
recipe: Mapped["RecipeModel"] = relationship("RecipeModel", back_populates="share_tokens", uselist=False)
|
||||
recipe: Mapped[RecipeModel] = relationship("RecipeModel", back_populates="share_tokens", uselist=False)
|
||||
|
||||
expires_at: FilterableColumn[datetime] = mapped_column(NaiveDateTime, nullable=False)
|
||||
|
||||
|
||||
@@ -51,12 +51,12 @@ class Tag(SqlAlchemyBase, BaseMixins):
|
||||
group_id: FilterableColumn[guid.GUID] = mapped_column(
|
||||
guid.GUID, sa.ForeignKey("groups.id"), nullable=False, index=True
|
||||
)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="tags", foreign_keys=[group_id])
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="tags", foreign_keys=[group_id])
|
||||
|
||||
name: FilterableColumn[str] = mapped_column(sa.String, index=True, nullable=False)
|
||||
slug: FilterableColumn[str] = mapped_column(sa.String, index=True, nullable=False)
|
||||
recipe_count: Mapped[int] = query_expression(default_expr=literal(0))
|
||||
recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel", secondary=recipes_to_tags, back_populates="tags"
|
||||
)
|
||||
|
||||
|
||||
@@ -46,15 +46,15 @@ class Tool(SqlAlchemyBase, BaseMixins):
|
||||
|
||||
# ID Relationships
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="tools", foreign_keys=[group_id])
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="tools", foreign_keys=[group_id])
|
||||
|
||||
name: FilterableColumn[str] = mapped_column(String, index=True, nullable=False)
|
||||
slug: FilterableColumn[str] = mapped_column(String, index=True, nullable=False)
|
||||
|
||||
households_with_tool: Mapped[list["Household"]] = orm.relationship(
|
||||
households_with_tool: Mapped[list[Household]] = orm.relationship(
|
||||
"Household", secondary=households_to_tools, back_populates="tools_on_hand"
|
||||
)
|
||||
recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel", secondary=recipes_to_tools, back_populates="tools"
|
||||
)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class ServerTaskModel(SqlAlchemyBase, BaseMixins):
|
||||
log: Mapped[str] = mapped_column(String, nullable=True)
|
||||
|
||||
group_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="server_tasks")
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="server_tasks")
|
||||
|
||||
@auto_init()
|
||||
def __init__(self, **_) -> None:
|
||||
|
||||
@@ -14,7 +14,7 @@ class PasswordResetModel(SqlAlchemyBase, BaseMixins):
|
||||
__tablename__ = "password_reset_tokens"
|
||||
|
||||
user_id: Mapped[GUID] = mapped_column(GUID, ForeignKey("users.id"), nullable=False, index=True)
|
||||
user: Mapped["User"] = orm.relationship("User", back_populates="password_reset_tokens", uselist=False)
|
||||
user: Mapped[User] = orm.relationship("User", back_populates="password_reset_tokens", uselist=False)
|
||||
token: Mapped[str] = mapped_column(String(64), unique=True, nullable=False)
|
||||
|
||||
def __init__(self, user_id, token, **_):
|
||||
|
||||
@@ -20,7 +20,7 @@ class UserToRecipe(SqlAlchemyBase, BaseMixins):
|
||||
id: Mapped[GUID] = mapped_column(GUID, primary_key=True, default=GUID.generate)
|
||||
|
||||
user_id = Column(GUID, ForeignKey("users.id"), index=True, primary_key=True)
|
||||
recipe: Mapped["RecipeModel"] = relationship("RecipeModel")
|
||||
recipe: Mapped[RecipeModel] = relationship("RecipeModel")
|
||||
recipe_id = Column(GUID, ForeignKey("recipes.id"), index=True, primary_key=True)
|
||||
group_id: AssociationProxy[GUID] = association_proxy("recipe", "group_id")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("recipe", "household_id")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import enum
|
||||
from datetime import UTC, datetime
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from pydantic import ConfigDict
|
||||
from sqlalchemy import Boolean, Enum, ForeignKey, Integer, String, orm, select
|
||||
@@ -31,7 +31,7 @@ class LongLiveToken(SqlAlchemyBase, BaseMixins):
|
||||
token: Mapped[str] = mapped_column(String, nullable=False, index=True)
|
||||
|
||||
user_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("users.id"), index=True)
|
||||
user: Mapped[Optional["User"]] = orm.relationship("User")
|
||||
user: Mapped[User | None] = orm.relationship("User")
|
||||
|
||||
group_id: AssociationProxy[GUID] = association_proxy("user", "group_id")
|
||||
household_id: AssociationProxy[GUID] = association_proxy("user", "household_id")
|
||||
@@ -61,11 +61,11 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
advanced: Mapped[bool | None] = mapped_column(Boolean, default=False)
|
||||
|
||||
group_id: FilterableColumn[GUID] = mapped_column(GUID, ForeignKey("groups.id"), nullable=False, index=True)
|
||||
group: Mapped["Group"] = orm.relationship("Group", back_populates="users")
|
||||
group: Mapped[Group] = orm.relationship("Group", back_populates="users")
|
||||
household_id: FilterableColumn[GUID | None] = mapped_column(
|
||||
GUID, ForeignKey("households.id"), nullable=True, index=True
|
||||
)
|
||||
household: Mapped["Household"] = orm.relationship("Household", back_populates="users")
|
||||
household: Mapped[Household] = orm.relationship("Household", back_populates="users")
|
||||
|
||||
cache_key: Mapped[str | None] = mapped_column(String, default="1234")
|
||||
# Digest of the OIDC picture claim the stored avatar was built from, so repeat logins
|
||||
@@ -94,25 +94,23 @@ class User(SqlAlchemyBase, BaseMixins):
|
||||
}
|
||||
|
||||
tokens: Mapped[list[LongLiveToken]] = orm.relationship(LongLiveToken, **sp_args)
|
||||
comments: Mapped[list["RecipeComment"]] = orm.relationship("RecipeComment", **sp_args)
|
||||
recipe_timeline_events: Mapped[list["RecipeTimelineEvent"]] = orm.relationship("RecipeTimelineEvent", **sp_args)
|
||||
password_reset_tokens: Mapped[list["PasswordResetModel"]] = orm.relationship("PasswordResetModel", **sp_args)
|
||||
comments: Mapped[list[RecipeComment]] = orm.relationship("RecipeComment", **sp_args)
|
||||
recipe_timeline_events: Mapped[list[RecipeTimelineEvent]] = orm.relationship("RecipeTimelineEvent", **sp_args)
|
||||
password_reset_tokens: Mapped[list[PasswordResetModel]] = orm.relationship("PasswordResetModel", **sp_args)
|
||||
|
||||
owned_recipes_id: Mapped[GUID | None] = mapped_column(GUID, ForeignKey("recipes.id"))
|
||||
owned_recipes: Mapped[Optional["RecipeModel"]] = orm.relationship(
|
||||
owned_recipes: Mapped[RecipeModel | None] = orm.relationship(
|
||||
"RecipeModel", single_parent=True, foreign_keys=[owned_recipes_id]
|
||||
)
|
||||
mealplans: Mapped[list["GroupMealPlan"]] = orm.relationship(
|
||||
"GroupMealPlan", order_by="GroupMealPlan.date", **sp_args
|
||||
)
|
||||
shopping_lists: Mapped[list["ShoppingList"]] = orm.relationship("ShoppingList", **sp_args)
|
||||
rated_recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
mealplans: Mapped[list[GroupMealPlan]] = orm.relationship("GroupMealPlan", order_by="GroupMealPlan.date", **sp_args)
|
||||
shopping_lists: Mapped[list[ShoppingList]] = orm.relationship("ShoppingList", **sp_args)
|
||||
rated_recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel",
|
||||
secondary=UserToRecipe.__tablename__,
|
||||
back_populates="rated_by",
|
||||
overlaps="recipe,favorited_by,favorited_recipes",
|
||||
)
|
||||
favorite_recipes: Mapped[list["RecipeModel"]] = orm.relationship(
|
||||
favorite_recipes: Mapped[list[RecipeModel]] = orm.relationship(
|
||||
"RecipeModel",
|
||||
secondary=UserToRecipe.__tablename__,
|
||||
primaryjoin="and_(User.id==UserToRecipe.user_id, UserToRecipe.is_favorite==True)",
|
||||
|
||||
@@ -75,7 +75,7 @@ class FetchResult:
|
||||
# Mirrors the decoding behavior of requests' `text` property.
|
||||
try:
|
||||
return str(self.content, self.encoding, errors="replace") # type: ignore[arg-type]
|
||||
except (LookupError, TypeError):
|
||||
except LookupError, TypeError:
|
||||
# LookupError: unknown encoding name. TypeError: encoding is None.
|
||||
return str(self.content, errors="replace")
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class RepositoryGeneric[Schema: MealieModel, Model: SqlAlchemyBase]:
|
||||
try:
|
||||
if isinstance(self.model.household_id, AssociationProxyInstance):
|
||||
q.filter(self.model.household_id.is_not(None))
|
||||
except (AttributeError, NotImplementedError):
|
||||
except AttributeError, NotImplementedError:
|
||||
pass
|
||||
|
||||
if with_options:
|
||||
|
||||
@@ -25,7 +25,7 @@ class IngredientUnitsSeeder(AbstractSeeder):
|
||||
def get_all_units(self) -> list[IngredientUnit]:
|
||||
return self.repos.ingredient_units.get_all()
|
||||
|
||||
def load_data(self, locale: str | None = None) -> Generator[SaveIngredientUnit, None, None]:
|
||||
def load_data(self, locale: str | None = None) -> Generator[SaveIngredientUnit]:
|
||||
file = self.get_file(locale)
|
||||
|
||||
seen_unit_names = {unit.name for unit in self.get_all_units()}
|
||||
@@ -97,7 +97,7 @@ class IngredientFoodsSeeder(AbstractSeeder):
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
|
||||
def load_data(self, locale: str | None = None) -> Generator[SaveIngredientFood, None, None]:
|
||||
def load_data(self, locale: str | None = None) -> Generator[SaveIngredientFood]:
|
||||
file = self.get_file(locale)
|
||||
|
||||
# de-duplicate on the localized name rather than the English seed key, otherwise seeding
|
||||
|
||||
@@ -9,7 +9,7 @@ class GroupStorage(MealieModel):
|
||||
total_storage_str: str
|
||||
|
||||
@classmethod
|
||||
def bytes(cls, used_storage_bytes: int, total_storage_bytes: int) -> "GroupStorage":
|
||||
def bytes(cls, used_storage_bytes: int, total_storage_bytes: int) -> GroupStorage:
|
||||
return cls(
|
||||
used_storage_bytes=used_storage_bytes,
|
||||
used_storage_str=fs_stats.pretty_size(used_storage_bytes),
|
||||
|
||||
@@ -34,7 +34,7 @@ class CategoryMerge(MealieModel):
|
||||
|
||||
|
||||
class RecipeCategoryResponse(CategoryBase):
|
||||
recipes: "list[RecipeSummary]" = []
|
||||
recipes: list[RecipeSummary] = []
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class RecipeToolOut(RecipeToolCreate):
|
||||
|
||||
|
||||
class RecipeToolResponse(RecipeToolOut):
|
||||
recipes: list["RecipeSummary"] = []
|
||||
recipes: list[RecipeSummary] = []
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -265,7 +265,9 @@ class AlchemyExporter(BaseService):
|
||||
from sqlalchemy.schema import DropConstraint, DropTable, MetaData, Table
|
||||
|
||||
with self.engine.begin() as connection:
|
||||
inspector = inspect(self.engine)
|
||||
# Inspect the open connection, not the engine: inspecting the engine checks out a
|
||||
# second connection that is only released when the inspector is garbage collected.
|
||||
inspector = inspect(connection)
|
||||
|
||||
# We need to re-create a minimal metadata with only the required things to
|
||||
# successfully emit drop constraints and tables commands for postgres (based
|
||||
|
||||
@@ -43,7 +43,7 @@ class EventListenerBase(ABC):
|
||||
...
|
||||
|
||||
@contextlib.contextmanager
|
||||
def ensure_session(self) -> Generator[Session, None, None]:
|
||||
def ensure_session(self) -> Generator[Session]:
|
||||
"""
|
||||
ensure_session ensures that a session is available for the caller by checking if a session
|
||||
was provided during construction, and if not, creating a new session with the `with_session`
|
||||
@@ -61,7 +61,7 @@ class EventListenerBase(ABC):
|
||||
yield self._session
|
||||
|
||||
@contextlib.contextmanager
|
||||
def ensure_repos(self, group_id: UUID4, household_id: UUID4) -> Generator[AllRepositories, None, None]:
|
||||
def ensure_repos(self, group_id: UUID4, household_id: UUID4) -> Generator[AllRepositories]:
|
||||
if self._repos is None:
|
||||
with self.ensure_session() as session:
|
||||
self._repos = AllRepositories(session, group_id=group_id, household_id=household_id)
|
||||
|
||||
@@ -115,7 +115,7 @@ def safe_local_path(candidate: str | Path, root: Path) -> Path | None:
|
||||
resolved = Path(candidate).resolve()
|
||||
if resolved.is_relative_to(root.resolve()):
|
||||
return resolved
|
||||
except (OSError, ValueError):
|
||||
except OSError, ValueError:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ def find_image(soup: bs4.BeautifulSoup) -> str | None:
|
||||
|
||||
try:
|
||||
size = int(width) * int(height)
|
||||
except (ValueError, TypeError):
|
||||
except ValueError, TypeError:
|
||||
size = 1
|
||||
if size > max_size:
|
||||
max_size = size
|
||||
|
||||
@@ -508,7 +508,7 @@ class RecipeService(RecipeServiceBase):
|
||||
for ing in ingredients:
|
||||
try:
|
||||
sub_recipe = self.get_one(ing.referenced_recipe.id)
|
||||
except (AttributeError, exceptions.NoEntryFound):
|
||||
except AttributeError, exceptions.NoEntryFound:
|
||||
continue
|
||||
|
||||
# Recursively check - path is modified in place and cleaned up via backtracking
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# https://github.com/dmontagu/fastapi-utils/blob/master/fastapi_utils/tasks.py
|
||||
|
||||
import asyncio
|
||||
import inspect
|
||||
import logging
|
||||
from asyncio import ensure_future
|
||||
from collections.abc import Callable, Coroutine
|
||||
@@ -51,7 +52,7 @@ def repeat_every(
|
||||
"""
|
||||
Converts the decorated function into a repeated, periodically-called version of itself.
|
||||
"""
|
||||
is_coroutine = asyncio.iscoroutinefunction(func)
|
||||
is_coroutine = inspect.iscoroutinefunction(func)
|
||||
|
||||
@wraps(func)
|
||||
async def wrapped() -> None:
|
||||
|
||||
@@ -292,7 +292,7 @@ class RecipeScraperPackage(ABCScraperStrategy):
|
||||
try:
|
||||
# scrape_html requires a URL, but we might not have one, so we default to a dummy URL
|
||||
scraped_schema = scrape_html(recipe_html, org_url=self.url or "https://example.com", supported_only=False)
|
||||
except (NoSchemaFoundInWildMode, AttributeError):
|
||||
except NoSchemaFoundInWildMode, AttributeError:
|
||||
self.logger.error(f"Recipe Scraper was unable to extract a recipe from {self.url}")
|
||||
return None
|
||||
|
||||
|
||||
+5
-4
@@ -4,7 +4,7 @@ version = "3.27.0"
|
||||
description = "A Recipe Manager"
|
||||
authors = [{ name = "Hayden", email = "hay-kot@pm.me" }]
|
||||
license = "AGPL-3.0-only"
|
||||
requires-python = ">=3.12,<3.13"
|
||||
requires-python = ">=3.14,<3.15"
|
||||
dependencies = [
|
||||
"Jinja2==3.1.6",
|
||||
"Pillow==12.3.0",
|
||||
@@ -110,7 +110,8 @@ filterwarnings = [
|
||||
"ignore::DeprecationWarning:pyRdfa.*",
|
||||
# Suppress Python 3.12 default SQLite datetime-adapter deprecation warning
|
||||
"ignore:The default datetime adapter is deprecated as of Python 3.12:DeprecationWarning",
|
||||
# Suppress anyio 4.15 BlockingPortal alias deprecation from starlette.testclient (fixed upstream, unreleased)
|
||||
# Suppress anyio 4.15 BlockingPortal alias deprecation from starlette.testclient.
|
||||
# Fixed in starlette 1.7.0; drop this once that version clears the exclude-newer window.
|
||||
"ignore:The anyio.abc.BlockingPortal alias is deprecated:DeprecationWarning",
|
||||
]
|
||||
|
||||
@@ -121,11 +122,11 @@ skip_empty = true
|
||||
follow_imports = "skip"
|
||||
ignore_missing_imports = true
|
||||
plugins = "pydantic.mypy"
|
||||
python_version = "3.12"
|
||||
python_version = "3.14"
|
||||
strict_optional = true
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py312"
|
||||
target-version = "py314"
|
||||
line-length = 120
|
||||
output-format = "concise"
|
||||
|
||||
|
||||
+1
-1
@@ -100,7 +100,7 @@ def test_image_png():
|
||||
|
||||
|
||||
@fixture(scope="session", autouse=True)
|
||||
def global_cleanup() -> Generator[None, None, None]:
|
||||
def global_cleanup() -> Generator[None]:
|
||||
"""Purges the .temp directory used for testing"""
|
||||
|
||||
yield None
|
||||
|
||||
Vendored
+2
-2
@@ -8,7 +8,7 @@ from mealie.repos.all_repositories import AllRepositories, get_repositories
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def session() -> Generator[sessionmaker[Session], None, None]:
|
||||
def session() -> Generator[sessionmaker[Session]]:
|
||||
try:
|
||||
sess = SessionLocal()
|
||||
yield sess
|
||||
@@ -17,5 +17,5 @@ def session() -> Generator[sessionmaker[Session], None, None]:
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def unfiltered_database(session: Session) -> Generator[AllRepositories, None, None]:
|
||||
def unfiltered_database(session: Session) -> Generator[AllRepositories]:
|
||||
yield get_repositories(session, group_id=None, household_id=None)
|
||||
Vendored
+2
-2
@@ -86,7 +86,7 @@ def recipes_ingredient_only(unique_user: TestUser):
|
||||
|
||||
|
||||
@fixture(scope="function")
|
||||
def recipe_categories(unique_user: TestUser) -> Generator[list[CategoryOut], None, None]:
|
||||
def recipe_categories(unique_user: TestUser) -> Generator[list[CategoryOut]]:
|
||||
database = unique_user.repos
|
||||
models: list[CategoryOut] = []
|
||||
for _ in range(3):
|
||||
@@ -105,7 +105,7 @@ def recipe_categories(unique_user: TestUser) -> Generator[list[CategoryOut], Non
|
||||
|
||||
|
||||
@fixture(scope="function")
|
||||
def random_recipe(unique_user: TestUser) -> Generator[Recipe, None, None]:
|
||||
def random_recipe(unique_user: TestUser) -> Generator[Recipe]:
|
||||
database = unique_user.repos
|
||||
recipe = Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
|
||||
Vendored
+1
-1
@@ -234,7 +234,7 @@ def unique_admin(session: Session, api_client: TestClient, unique_user: utils.Te
|
||||
|
||||
|
||||
@fixture(scope="module")
|
||||
def user_tuple(session: Session, admin_token, api_client: TestClient) -> Generator[list[utils.TestUser], None, None]:
|
||||
def user_tuple(session: Session, admin_token, api_client: TestClient) -> Generator[list[utils.TestUser]]:
|
||||
group_name = utils.random_string()
|
||||
|
||||
# Create the user
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from uuid import UUID
|
||||
|
||||
from dateutil.parser import parse as parse_dt
|
||||
@@ -55,7 +55,7 @@ def test_get_household_recipe_default(api_client: TestClient, unique_user: TestU
|
||||
|
||||
|
||||
def test_get_household_recipe(api_client: TestClient, unique_user: TestUser, h2_user: TestUser):
|
||||
dt_now = datetime.now(tz=timezone.utc)
|
||||
dt_now = datetime.now(tz=UTC)
|
||||
recipe = unique_user.repos.recipes.create(
|
||||
Recipe(
|
||||
user_id=unique_user.user_id,
|
||||
|
||||
@@ -15,7 +15,7 @@ from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def ten_slugs(api_client: TestClient, unique_user: TestUser) -> Generator[list[str], None, None]:
|
||||
def ten_slugs(api_client: TestClient, unique_user: TestUser) -> Generator[list[str]]:
|
||||
database = unique_user.repos
|
||||
slugs: list[str] = []
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ def html_fetch_result(html: str, url: str) -> FetchResult:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def ai_providers(unique_user: TestUser) -> Generator[None, None, None]:
|
||||
def ai_providers(unique_user: TestUser) -> Generator[None]:
|
||||
"""Enable both the default and image providers, restoring the original settings afterwards."""
|
||||
|
||||
provider = unique_user.repos.group_ai_providers.create(
|
||||
@@ -118,7 +118,7 @@ class AIResponses:
|
||||
self.prompts: list[str] = []
|
||||
self.messages: list[str] = []
|
||||
|
||||
def install(self, monkeypatch: pytest.MonkeyPatch) -> "AIResponses":
|
||||
def install(self, monkeypatch: pytest.MonkeyPatch) -> AIResponses:
|
||||
responses = self
|
||||
|
||||
async def mock_get_response(self, prompt, message, *args, response_schema=None, **kwargs):
|
||||
|
||||
@@ -48,21 +48,21 @@ recipe_test_data = get_recipe_test_cases()
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def tempdir() -> Generator[str, None, None]:
|
||||
def tempdir() -> Generator[str]:
|
||||
with tempfile.TemporaryDirectory() as td:
|
||||
yield td
|
||||
|
||||
|
||||
def zip_recipe(tempdir: str, recipe: RecipeSummary) -> dict:
|
||||
data_file = tempfile.NamedTemporaryFile(mode="w+", dir=tempdir, suffix=".json", delete=False)
|
||||
json.dump(json.loads(recipe.model_dump_json()), data_file)
|
||||
data_file.flush()
|
||||
with tempfile.NamedTemporaryFile(mode="w+", dir=tempdir, suffix=".json", delete=False) as data_file:
|
||||
json.dump(json.loads(recipe.model_dump_json()), data_file)
|
||||
data_file.flush()
|
||||
|
||||
zip_file = os.path.join(tempdir, "zipfile.zip")
|
||||
with ZipFile(zip_file, "w") as zf:
|
||||
zf.write(data_file.name)
|
||||
zip_file = os.path.join(tempdir, "zipfile.zip")
|
||||
with ZipFile(zip_file, "w") as zf:
|
||||
zf.write(data_file.name)
|
||||
|
||||
return {"archive": Path(zip_file).read_bytes()}
|
||||
return {"archive": Path(zip_file).read_bytes()}
|
||||
|
||||
|
||||
def get_init(html_path: Path):
|
||||
|
||||
@@ -11,7 +11,7 @@ from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def food(api_client: TestClient, unique_user: TestUser) -> Generator[dict, None, None]:
|
||||
def food(api_client: TestClient, unique_user: TestUser) -> Generator[dict]:
|
||||
data = CreateIngredientFood(
|
||||
name=random_string(10),
|
||||
description=random_string(10),
|
||||
|
||||
@@ -12,7 +12,7 @@ from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def recipes(user_tuple: tuple[TestUser, TestUser]) -> Generator[list[Recipe], None, None]:
|
||||
def recipes(user_tuple: tuple[TestUser, TestUser]) -> Generator[list[Recipe]]:
|
||||
unique_user = random.choice(user_tuple)
|
||||
database = unique_user.repos
|
||||
recipes_repo = database.recipes
|
||||
|
||||
@@ -12,7 +12,7 @@ from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def slug(api_client: TestClient, unique_user: TestUser) -> Generator[str, None, None]:
|
||||
def slug(api_client: TestClient, unique_user: TestUser) -> Generator[str]:
|
||||
database = unique_user.repos
|
||||
payload = {"name": random_string(length=20)}
|
||||
response = api_client.post(api_routes.recipes, json=payload, headers=unique_user.token)
|
||||
|
||||
@@ -18,7 +18,6 @@ from tests.utils import api_routes
|
||||
from tests.utils.factories import random_string
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
PERSISTED_TRANSLATION_KEYS = [RECIPE_CREATED_EVENT_SUBJECT]
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ def test_alchemy_exporter():
|
||||
assert data["alembic_version"] == alembic_versions()
|
||||
assert json.dumps(data, indent=4) # Make sure data is json-serializable
|
||||
|
||||
exporter.engine.dispose()
|
||||
|
||||
|
||||
def test_every_datetime_column_survives_a_backup():
|
||||
"""Restores rebuild datetimes by column name, so an unregistered one comes back as a string.
|
||||
|
||||
@@ -41,6 +41,8 @@ def test_database_backup():
|
||||
with backup as contents:
|
||||
assert contents.validate()
|
||||
|
||||
backup_v2.db_exporter.engine.dispose()
|
||||
|
||||
|
||||
def test_database_restore():
|
||||
settings = get_app_settings()
|
||||
@@ -48,6 +50,7 @@ def test_database_restore():
|
||||
# Capture existing database snapshot
|
||||
original_exporter = AlchemyExporter(settings.DB_URL)
|
||||
snapshop_1 = original_exporter.dump()
|
||||
original_exporter.engine.dispose()
|
||||
|
||||
# Create Backup
|
||||
backup_v2 = BackupV2(settings.DB_URL)
|
||||
@@ -58,6 +61,7 @@ def test_database_restore():
|
||||
|
||||
new_exporter = AlchemyExporter(settings.DB_URL)
|
||||
snapshop_2 = new_exporter.dump()
|
||||
new_exporter.engine.dispose()
|
||||
|
||||
for s1, s2 in zip(snapshop_1, snapshop_2, strict=False):
|
||||
assert snapshop_1[s1].sort(key=dict_sorter) == snapshop_2[s2].sort(key=dict_sorter)
|
||||
|
||||
@@ -66,6 +66,8 @@ def test_embedded_over_plain_http_stays_lax():
|
||||
assert attrs["samesite"] == "lax"
|
||||
|
||||
|
||||
# TODO: now that we're on 3.14, `Partitioned` can actually be emitted. Revisit whether embedded
|
||||
# cookies should set it (CHIPS), and update this test and `test_embedded_https_cookie_is_actually_sendable`.
|
||||
def test_no_attribute_starlette_cannot_emit():
|
||||
"""`Partitioned` needs Python 3.14; asking for it on 3.12 made every embedded login a 500."""
|
||||
assert "partitioned" not in session_cookie_attrs(
|
||||
|
||||
Reference in new issue
Block a user