Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8cd582

Browse files
authored
nodes: fix failing tests (#992)
1 parent ddc9c99 commit f8cd582

File tree

15 files changed

+448
-212
lines changed

15 files changed

+448
-212
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""title constraint for the folder
2+
3+
Revision ID: 45b268a785c2
4+
Revises: e077d2695f3f
5+
Create Date: 2025年10月16日 06:44:12.939335
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
# revision identifiers, used by Alembic.
14+
revision: str = '45b268a785c2'
15+
down_revision: Union[str, None] = 'e077d2695f3f'
16+
branch_labels: Union[str, Sequence[str], None] = None
17+
depends_on: Union[str, Sequence[str], None] = None
18+
19+
20+
def upgrade() -> None:
21+
op.create_index('idx_nodes_unique_folder_title_parent', 'nodes', ['title', 'parent_id'], unique=True, postgresql_where=sa.text("ctype = 'folder'"))
22+
23+
24+
def downgrade() -> None:
25+
op.drop_index('idx_nodes_unique_folder_title_parent', table_name='nodes', postgresql_where=sa.text("ctype = 'folder'"))

‎papermerge/core/features/conftest.py‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,6 @@ async def _make_tax(title: str, user: orm.User, parent=None):
864864
async def make_group(db_session: AsyncSession):
865865
"""Create test group, optionally with special folders"""
866866
async def _maker(name: str, with_special_folders: bool = False):
867-
# REMOVED: await db_session.execute(text("SET CONSTRAINTS ALL DEFERRED"))
868-
869867
from papermerge.core.features.special_folders.db import api as special_folders_api
870868

871869
group_id = uuid.uuid4()
@@ -886,16 +884,7 @@ async def _maker(name: str, with_special_folders: bool = False):
886884
)
887885

888886
await db_session.commit()
889-
890-
# Reload with relationships
891-
stmt = (
892-
select(orm.Group)
893-
.options(
894-
selectinload(orm.Group.special_folders)
895-
).where(orm.Group.id == group.id)
896-
)
897-
result = await db_session.execute(stmt)
898-
group = result.scalar_one()
887+
await db_session.refresh(group)
899888

900889
return group
901890

‎papermerge/core/features/document/schema.py‎

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,14 @@ def thumbnail_url(value, info):
198198
ThumbnailUrl = Annotated[str | None, Field(validate_default=True)]
199199

200200

201-
class DocumentNode(BaseModel):
202-
"""Document without versions
203-
204-
The point of this class is to be used when listing folders/documents in
205-
which case info about document versions (and their pages etc) is not
206-
required (generating document version info in context of CDN is very
207-
slow as for each page of each doc ver signed URL must be computed)
208-
"""
209-
201+
class DocumentBase(BaseModel):
210202
id: UUID
211203
title: str
212204
ctype: Literal["document"]
213205
tags: list[Tag] = Field(default_factory=list)
214-
# created_at: datetime
215-
# updated_at: datetime
216206
parent_id: UUID | None
217-
document_type_id: UUID | None = None
218-
breadcrumb: list[tuple[UUID, str]] = Field(default_factory=list)
219-
ocr: bool = True # will this document be OCRed?
220-
ocr_status: OCRStatusEnum = OCRStatusEnum.unknown
221-
thumbnail_url: ThumbnailUrl = None
222207
preview_status: str | None = None
223-
user_id: UUID | None = None
224-
group_id: UUID | None = None
225-
owner_name: str | None = None
226-
perms: list[str] = Field(default_factory=list)
227-
is_shared: bool = False
208+
thumbnail_url: ThumbnailUrl = None
228209

229210
@field_validator("thumbnail_url", mode="before")
230211
def thumbnail_url_validator(cls, value, info):
@@ -250,10 +231,34 @@ def thumbnail_url_validator(cls, value, info):
250231
model_config = ConfigDict(from_attributes=True)
251232

252233

234+
class DocumentNode(DocumentBase):
235+
"""Document without versions
236+
237+
The point of this class is to be used when listing folders/documents in
238+
which case info about document versions (and their pages etc) is not
239+
required (generating document version info in context of CDN is very
240+
slow as for each page of each doc ver signed URL must be computed)
241+
"""
242+
document_type_id: UUID | None = None
243+
breadcrumb: list[tuple[UUID, str]] = Field(default_factory=list)
244+
ocr: bool = True # will this document be OCRed?
245+
ocr_status: OCRStatusEnum = OCRStatusEnum.unknown
246+
owner_name: str | None = None
247+
perms: list[str] = Field(default_factory=list)
248+
is_shared: bool = False
249+
250+
# Config
251+
model_config = ConfigDict(from_attributes=True)
252+
253+
253254
class Document(DocumentNode):
254255
versions: list[DocumentVersion] = Field(default_factory=list)
255256

256257

258+
class DocumentShort(DocumentBase):
259+
pass
260+
261+
257262
class DocumentWithoutVersions(DocumentNode):
258263
...
259264

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /