Skip to content

fix(optimise-framework-schema): move framework feature fields to JSON… - #1249

Merged
JayGhiya merged 1 commit into
devfrom
optimise-schema-framework
Feb 21, 2026
Merged

fix(optimise-framework-schema): move framework feature fields to JSON…#1249
JayGhiya merged 1 commit into
devfrom
optimise-schema-framework

Conversation

@JayGhiya

Copy link
Copy Markdown
Member

…B payload

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: UNOPL-1395

@claude

claude Bot commented Feb 21, 2026

Copy link
Copy Markdown

Claude finished @JayGhiya's task —— View job


PR Review: Framework Schema Optimization

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze modified files and understand schema changes
  • Review code quality and best practices
  • Check for potential bugs and security issues
  • Evaluate performance implications
  • Assess test coverage needs
  • Provide comprehensive feedback

Overall Assessment

This is a well-executed schema refactoring that moves framework feature fields into a JSONB payload. The changes maintain backward compatibility through properties while enabling more flexible schema evolution.

🔍 Code Quality & Best Practices

Strengths:

  • Clean separation of concerns: FrameworkFeaturePayload in engine_models.py provides a clear Pydantic model for the JSONB structure
  • Backward compatibility: Properties maintain the same API surface area (framework_models.py:102-160)
  • Type safety: Proper type annotations and enum handling with validation
  • Performance optimization: Added GIN indexes for JSONB queries (framework_models.py:66-74)
  • Consistent error handling: TypeErrors with descriptive messages for invalid data types

Minor improvements suggested:

  • Consider adding @property decorators with @cached_property for properties that don't change frequently to avoid repeated JSONB parsing overhead
  • The construct_query_typed setter logic (framework_models.py:183-192) could benefit from a helper method to reduce complexity

🐛 Potential Issues

Critical - Test Compatibility:
The existing test file test_framework_definitions_ingestion.py:66-80 still creates FrameworkFeature objects using the old direct field assignment pattern:

FrameworkFeature(
    language=language,
    library=library_name,
    feature_key=feature_key,
    description=feature_data.get("description"),     # ❌ No longer a direct field
    target_level=feature_data.get("target_level"),   # ❌ No longer a direct field
    concept=feature_data.get("concept"),             # ❌ No longer a direct field
    # ... other removed fields
)

This will cause test failures because these fields are now stored in the feature_definition JSONB field.

Moderate Issues:

  1. Missing validation in property getters for startpoint (framework_models.py:154-159) - it assumes the key exists but should handle missing keys with a default
  2. Extra="allow" in FrameworkFeaturePayload (engine_models.py:141) might allow unintended fields - consider extra="forbid" for stricter validation

Performance Considerations

Positive:

  • GIN indexes on JSONB fields will significantly improve query performance for feature definition searches
  • Startpoint boolean index enables fast filtering for entry point features
  • JSONB storage is more efficient than multiple columns for sparse data

Watch for:

  • Property access patterns may be slightly slower due to JSONB parsing, but this is negligible for most use cases
  • Consider monitoring query performance with the new indexes in production

🔒 Security

No significant concerns identified:

  • JSONB field has proper default and server_default values
  • Type validation in properties prevents injection through malformed data
  • Foreign key constraints maintain referential integrity

🧪 Test Coverage

Action Required:
The test parsing function in test_framework_definitions_ingestion.py:66-80 needs updating to use the new JSONB schema:

# Current (broken):
FrameworkFeature(
    description=feature_data.get("description"),
    target_level=feature_data.get("target_level", "function"),
    # ...
)

# Should be:
FrameworkFeature(
    language=language,
    library=library_name, 
    feature_key=feature_key,
    feature_definition={
        "description": feature_data.get("description"),
        "target_level": feature_data.get("target_level", "function"),
        "concept": feature_data.get("concept", "AnnotationLike"),
        "locator_strategy": feature_data.get("locator_strategy", "VariableBound"),
        "construct_query": feature_data.get("construct_query"),
        "startpoint": feature_data.get("startpoint", False),
    }
)

Test files that likely need attention:

  • test_framework_definitions_ingestion.py:66-80 ⚠️ Will fail
  • test_framework_detection_with_postgres.py - May need review for property access patterns

🚀 Recommendations

  1. Fix test compatibility by updating the parse_json_data function to use the new JSONB schema
  2. Add missing key handling in the startpoint property getter
  3. Consider extra="forbid" for FrameworkFeaturePayload for stricter validation
  4. Run tests to ensure no regressions before merging

📊 Schema Migration Impact

This change represents a significant schema evolution that:

  • ✅ Maintains API compatibility through properties
  • ✅ Improves query performance with JSONB indexes
  • ✅ Enables future schema flexibility
  • ⚠️ Requires test updates to prevent failures

@JayGhiya
JayGhiya merged commit ccf65ec into dev Feb 21, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de6f1445d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +85 to +89
feature_definition: Mapped[dict[str, object]] = mapped_column(
JSONB,
nullable=True,
default=None,
comment="Language-specific query tweaks for adapter construction",
)
description: Mapped[Optional[str]] = mapped_column(default=None)
startpoint: Mapped[bool] = mapped_column(
default=False,
comment="Indicates whether this feature represents a starting point or entry point in the application"
nullable=False,
default=dict,
server_default=text("'{}'::jsonb"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore keyword initialization for moved feature fields

FrameworkFeature no longer maps description, target_level, concept, locator_strategy, construct_query, or startpoint as ORM attributes, so the existing constructor calls that still pass these kwargs now fail at runtime (e.g. framework_loader.parse_json_data in code-confluence-flow-bridge creates FrameworkFeature(..., target_level=..., concept=..., ...)). With this commit, SQLAlchemy’s declarative constructor will raise TypeError for those unexpected keyword arguments, which prevents framework definition ingestion from loading at startup.

Useful? React with 👍 / 👎.

Comment on lines +154 to +157
def startpoint(self) -> bool:
"""Return startpoint from feature_definition."""
value = self.feature_definition["startpoint"]
if isinstance(value, bool):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Make startpoint queryable after converting it to JSON property

After this change, startpoint is a plain Python @property, so class-level uses like select(FrameworkFeature.startpoint) no longer produce a SQL expression and instead pass a property object; query construction in code_confluence_framework_repository.py currently does exactly that in two read paths. This causes runtime query failures for framework-feature lookups unless all call sites are rewritten to use startpoint_sql_expression() (or the model exposes a hybrid/expression-backed attribute).

Useful? React with 👍 / 👎.

JayGhiya added a commit that referenced this pull request Apr 8, 2026
fix(optimise-framework-schema): move framework feature fields to JSON…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant