← Back to Pull requests

Keep API imports consistent with file imports #108

Merged
nessita merged 11 files (1375 lines) on Nov 20, 2026 20:25 UTC
View on GitHub
nessita nessita commented on Nov 17, 2026 16:03 UTC
Author

API imports now use the same regex rules as file imports.
Rules can assign tags and assets, and create transfer counterparts.
Explicit tags and assets override inferred values.
An entry and its transfer counterpart either both save or neither does.
Invalid rows do not stop other valid rows.
Shared lookups are reused within each batch.
A new test helper checks whether adding more items causes extra queries.
Added tests for these behaviors. You still need to run tests and linters.

Diff: 1375 lines (+1271 / -104) across 11 files Reviewer: nessita Review duration: 4581m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.72) × (1 − Review Confidence (0.77)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 1375 lines diff across 11 files
0.72
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.74 · 2 substantive comment(s)
0.74
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
76%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Self Review self_review
0.140
Real PR Conversation Timeline
4 items
Copilot Copilot commented on code on Nov 20, 2026 13:54 UTC
Code Review
gemcore/models.py:1
@@ -401,12 +414,65 @@ def save(self, *args, **kwargs):
 
     def tags_for(self, value):
         tags = {}
-        for tagregex in self.tagregex_set.all():
-            pattern = re.compile(tagregex.regex)
-            if pattern.match(value):
-                tags[tagregex.tag] = (tagregex.transfer, tagregex.asset)
+        for tagregex in self.matching_tag_regexes(value):
+            tags[tagregex.tag] = (tagregex.transfer, tagregex.asset)
         return tags
 
+    def matching_tag_regexes(self, value):
+        tagregexes = getattr(self, "prefetched_tagregexes", None)
+        if tagregexes is None:
+            tagregexes = self.tagregex_set.select_related("transfer", "asset")
+        for tagregex in tagregexes:
+            if re.match(tagregex.regex, value):
+                yield tagregex

A stored regex such as [ raises re.error here. TagRegex.regex has no regex validator, and the API only converts Django ValidationError into row errors, so this produces a 500 and stops later valid rows in a bulk request. It now also affects explicitly tagged requests, which previously skipped rule matching. Convert malformed-regex errors into ValidationError so the API can reject just the affected row.

copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 13:54 UTC
Reviewer

<!-- ccr-overview-v2 -->

🟡 Changes recommended

A malformed stored regex can cause a 500 and halt valid rows in a bulk request, including explicitly tagged requests, instead of being handled as a row-level validation error.

<details open>
<summary><strong>1 open issue</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Malformed stored regex causes bulk requests to fail with 500 · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Aligns API entry creation with file imports by sharing regex-based inference, validation, and transactional saving.

    Changes:

  • Applies account regexes to tags, assets, and transfer counterparts while preserving explicit tag and asset choices.

  • Saves source entries and transfer counterparts together, with row-level error handling.

  • Reuses batch lookups and adds behavioral tests, a query-count helper, and API documentation.
  • Tests and linters were not run.

    | File | Description |
    | ---- | ----------- |
    | README.md | Documents asset overrides, regex inference, and transfer behavior. |
    | gemcore/​tests/​test_views.py | Tests the query-count assertion helper. |
    | gemcore/​tests/​test_parser.py | Covers deferred fees, transfers, rollback, and lookup reuse. |
    | gemcore/​tests/​test_models.py | Tests regex prefetching and query-free resolution. |
    | gemcore/​tests/​helpers.py | Adds a helper for detecting query-count growth. |
    | gemcore/​parser.py | Routes CSV imports through shared resolution and creation logic. |
    | gemcore/​models.py | Adds shared regex resolution and prefetching. |
    | gemcore/​forms.py | Centralizes transactional entry and counterpart creation. |
    | gemapi/​views.py | Eager-loads assets for entry responses. |
    | gemapi/​tests.py | Tests import parity, overrides, transfers, and query counts. |
    | gemapi/​serializers.py | Adds asset support, cached lookups, and shared entry creation. |
    </details>

    <sub>Review effort: Balanced</sub>

    nessita nessita commented on code on Nov 20, 2026 14:25 UTC
    Code Review
    gemcore/models.py:1
    @@ -401,12 +414,65 @@ def save(self, *args, **kwargs):
     
         def tags_for(self, value):
             tags = {}
    -        for tagregex in self.tagregex_set.all():
    -            pattern = re.compile(tagregex.regex)
    -            if pattern.match(value):
    -                tags[tagregex.tag] = (tagregex.transfer, tagregex.asset)
    +        for tagregex in self.matching_tag_regexes(value):
    +            tags[tagregex.tag] = (tagregex.transfer, tagregex.asset)
             return tags
     
    +    def matching_tag_regexes(self, value):
    +        tagregexes = getattr(self, "prefetched_tagregexes", None)
    +        if tagregexes is None:
    +            tagregexes = self.tagregex_set.select_related("transfer", "asset")
    +        for tagregex in tagregexes:
    +            if re.match(tagregex.regex, value):
    +                yield tagregex

    This is tracked in #110.

    Reviewers
    Assignees
    nessita nessita
    Labels
    risk: low confidence: 77.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.7% (HIGH) · Higher = larger blast radius
    71.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 77.0% · Lower = rushed or shallow review
    77.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.5% · Safe to merge
    16.5%
    Repository