Fixing string padding in import
This commit is contained in:
1 parent
a0bd7f2c27
commit
aca15db9bf
3 files changed
+21
-43
No files matched your search
@@ -109,9 +109,7 @@ async def _get_or_create_attachment_point_name(db: AsyncSession, name: str):
|
||||
return apn
|
||||
|
||||
|
||||
async def _add_attachment_point(
|
||||
db: AsyncSession, ap: AugmentedPart, ip: ImportedPart
|
||||
) -> None:
|
||||
async def _add_attachment_point(db: AsyncSession, ap: AugmentedPart, ip: ImportedPart) -> None:
|
||||
"""Infer and create an attachment point for a newly-synced AugmentedPart.
|
||||
|
||||
Preference order: TBXThreadAttribute (ISO/UNC thread) then ProductODmm/in
|
||||
@@ -127,9 +125,7 @@ async def _add_attachment_point(
|
||||
|
||||
if kind == "iso":
|
||||
depth_mm = _parse_float(ip.ProductMaxThreadDepthmm)
|
||||
thread = await iso_thread_crud.get_by_values(
|
||||
db, depth_mm=depth_mm, **fields
|
||||
)
|
||||
thread = await iso_thread_crud.get_by_values(db, depth_mm=depth_mm, **fields)
|
||||
if thread is None:
|
||||
thread = await iso_thread_crud.create(db, depth_mm=depth_mm, **fields)
|
||||
await attachment_point_crud.create(
|
||||
@@ -140,9 +136,7 @@ async def _add_attachment_point(
|
||||
)
|
||||
elif kind == "unc":
|
||||
depth_in = _parse_float(ip.ProductMaxThreadDepthin)
|
||||
thread = await unc_thread_crud.get_by_values(
|
||||
db, depth_in=depth_in, **fields
|
||||
)
|
||||
thread = await unc_thread_crud.get_by_values(db, depth_in=depth_in, **fields)
|
||||
if thread is None:
|
||||
thread = await unc_thread_crud.create(db, depth_in=depth_in, **fields)
|
||||
await attachment_point_crud.create(
|
||||
@@ -201,7 +195,7 @@ async def sync_one(
|
||||
manufacturer = await manufacturer_crud.create(db, name="Armament", url="")
|
||||
|
||||
ap = AugmentedPart(
|
||||
sku=None,
|
||||
sku=ip.InventoryID,
|
||||
description=description,
|
||||
colour_id=colour.id,
|
||||
manufacturer_id=manufacturer.id,
|
||||
@@ -240,9 +234,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
|
||||
# ------------------------------------------------------------------ phase 1
|
||||
|
||||
# IDs referenced in existing associations
|
||||
result = await db.execute(
|
||||
select(augmented_part_imported_parts.c.imported_part_id).distinct()
|
||||
)
|
||||
result = await db.execute(select(augmented_part_imported_parts.c.imported_part_id).distinct())
|
||||
all_linked_ids: set[str] = {row[0] for row in result.all()}
|
||||
|
||||
# IDs that still exist in imported_parts
|
||||
@@ -256,9 +248,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
|
||||
# Which AugmentedParts are affected?
|
||||
result = await db.execute(
|
||||
select(augmented_part_imported_parts.c.augmented_part_id).where(
|
||||
augmented_part_imported_parts.c.imported_part_id.in_(
|
||||
orphaned_import_ids
|
||||
)
|
||||
augmented_part_imported_parts.c.imported_part_id.in_(orphaned_import_ids)
|
||||
)
|
||||
)
|
||||
orphaned_ap_ids: set[int] = {row[0] for row in result.all()}
|
||||
@@ -266,9 +256,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
|
||||
# Remove the stale association rows
|
||||
await db.execute(
|
||||
augmented_part_imported_parts.delete().where(
|
||||
augmented_part_imported_parts.c.imported_part_id.in_(
|
||||
orphaned_import_ids
|
||||
)
|
||||
augmented_part_imported_parts.c.imported_part_id.in_(orphaned_import_ids)
|
||||
)
|
||||
)
|
||||
await db.flush()
|
||||
@@ -291,9 +279,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
|
||||
# ------------------------------------------------------------------ phase 2
|
||||
|
||||
# Re-query linked IDs after phase 1 cleanup
|
||||
result = await db.execute(
|
||||
select(augmented_part_imported_parts.c.imported_part_id).distinct()
|
||||
)
|
||||
result = await db.execute(select(augmented_part_imported_parts.c.imported_part_id).distinct())
|
||||
now_linked_ids: set[str] = {row[0] for row in result.all()}
|
||||
unlinked_ids = current_ids - now_linked_ids
|
||||
|
||||
@@ -301,9 +287,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
|
||||
skipped = 0
|
||||
|
||||
if not unlinked_ids:
|
||||
return AugmentedPartSyncResult(
|
||||
created=created, deleted=deleted, skipped=skipped
|
||||
)
|
||||
return AugmentedPartSyncResult(created=created, deleted=deleted, skipped=skipped)
|
||||
|
||||
result = await db.execute(
|
||||
select(ImportedPart).where(ImportedPart.InventoryID.in_(unlinked_ids))
|
||||
@@ -331,7 +315,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
|
||||
colour = await part_colour_crud.create(db, name=colour_name)
|
||||
|
||||
ap = AugmentedPart(
|
||||
sku=None,
|
||||
sku=ip.InventoryID,
|
||||
description=description,
|
||||
colour_id=colour.id,
|
||||
manufacturer_id=manufacturer.id,
|
||||
|
||||
Reference in new issue
Block a user