mirror of
https://github.com/johndoe6345789/goodpackagerepo.git
synced 2026-04-24 13:54:59 +00:00
Fix code review issues: use Boolean types, add error handling, remove unused imports
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -26,8 +26,12 @@ CORS(app)
|
||||
|
||||
# Load schema.json for reference
|
||||
SCHEMA_PATH = Path(__file__).parent.parent / "schema.json"
|
||||
with open(SCHEMA_PATH) as f:
|
||||
SCHEMA = json.load(f)
|
||||
try:
|
||||
with open(SCHEMA_PATH) as f:
|
||||
SCHEMA = json.load(f)
|
||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||
print(f"Error loading schema.json: {e}")
|
||||
SCHEMA = {"ops": {"limits": {"max_request_body_bytes": 2147483648}}} # Default fallback
|
||||
|
||||
# Configuration is now loaded from database using SQLAlchemy
|
||||
# schema.json is only used once during initial database setup
|
||||
|
||||
@@ -71,7 +71,7 @@ def load_schema_to_db(schema_path: Path):
|
||||
entity_id=entity.id,
|
||||
name=field_name,
|
||||
type=field_data['type'],
|
||||
optional=1 if field_data.get('optional', False) else 0,
|
||||
optional=field_data.get('optional', False),
|
||||
normalizations=json.dumps(field_data.get('normalize', []))
|
||||
)
|
||||
session.add(field)
|
||||
@@ -82,7 +82,7 @@ def load_schema_to_db(schema_path: Path):
|
||||
entity_id=entity.id,
|
||||
field=constraint['field'],
|
||||
regex=constraint['regex'],
|
||||
when_present=1 if constraint.get('when_present', False) else 0
|
||||
when_present=constraint.get('when_present', False)
|
||||
)
|
||||
session.add(constraint_obj)
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@ This module defines the database schema using SQLAlchemy ORM.
|
||||
|
||||
from datetime import datetime
|
||||
from sqlalchemy import (
|
||||
create_engine, Column, Integer, String, Text, Boolean, ForeignKey,
|
||||
Table, MetaData
|
||||
create_engine, Column, Integer, String, Text, Boolean, ForeignKey
|
||||
)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import relationship, sessionmaker
|
||||
@@ -111,7 +110,7 @@ class EntityField(ConfigBase):
|
||||
entity_id = Column(Integer, ForeignKey('entities.id', ondelete='CASCADE'), nullable=False)
|
||||
name = Column(String(255), nullable=False)
|
||||
type = Column(String(64), nullable=False)
|
||||
optional = Column(Integer, default=0)
|
||||
optional = Column(Boolean, default=False)
|
||||
normalizations = Column(Text) # JSON
|
||||
|
||||
entity = relationship("Entity", back_populates="fields")
|
||||
@@ -125,7 +124,7 @@ class EntityConstraint(ConfigBase):
|
||||
entity_id = Column(Integer, ForeignKey('entities.id', ondelete='CASCADE'), nullable=False)
|
||||
field = Column(String(255), nullable=False)
|
||||
regex = Column(Text, nullable=False)
|
||||
when_present = Column(Integer, default=0)
|
||||
when_present = Column(Boolean, default=False)
|
||||
|
||||
entity = relationship("Entity", back_populates="constraints")
|
||||
|
||||
|
||||
@@ -53,8 +53,12 @@ def publish_package(token: str, package: Dict[str, Any]) -> None:
|
||||
response = requests.put(url, headers=headers, data=content)
|
||||
|
||||
if response.status_code == 201:
|
||||
data = response.json()
|
||||
print(f"✅ Published {namespace}/{name}:{version}@{variant} (digest: {data['digest'][:16]}...)")
|
||||
try:
|
||||
data = response.json()
|
||||
digest = data.get('digest', 'unknown')
|
||||
print(f"✅ Published {namespace}/{name}:{version}@{variant} (digest: {digest[:16]}...)")
|
||||
except (ValueError, KeyError):
|
||||
print(f"✅ Published {namespace}/{name}:{version}@{variant}")
|
||||
elif response.status_code == 409:
|
||||
print(f"⚠️ Package {namespace}/{name}:{version}@{variant} already exists, skipping")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user