Skip to content

Commit 9cbadd2

Browse files
authored
Merge pull request #94 from ds1sqe/develop
1.2.7 - TypeDB 3.8.0 Support and Batch Operations Optimization
2 parents 9fd510f + 22e3a91 commit 9cbadd2

147 files changed

Lines changed: 11519 additions & 9529 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
# Ensure only one release workflow runs at a time
9+
concurrency:
10+
group: release
11+
cancel-in-progress: false
12+
13+
jobs:
14+
# Run tests before releasing
15+
test:
16+
name: Test
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.13"
26+
27+
- name: Install uv
28+
uses: astral-sh/setup-uv@v5
29+
with:
30+
enable-cache: true
31+
32+
- name: Install dependencies
33+
run: uv sync --extra dev
34+
35+
- name: Run linting
36+
run: uv run ruff check .
37+
38+
- name: Run unit tests
39+
run: uv run pytest tests/unit/ -v --tb=short
40+
41+
# Build the package
42+
build:
43+
name: Build
44+
needs: test
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Set up Python
51+
uses: actions/setup-python@v5
52+
with:
53+
python-version: "3.13"
54+
55+
- name: Install uv
56+
uses: astral-sh/setup-uv@v5
57+
with:
58+
enable-cache: true
59+
60+
- name: Build package
61+
run: uv build
62+
63+
- name: Upload build artifacts
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: dist
67+
path: dist/
68+
69+
# Publish to PyPI
70+
publish-pypi:
71+
name: Publish to PyPI
72+
needs: build
73+
runs-on: ubuntu-latest
74+
environment: release
75+
permissions:
76+
id-token: write # Required for trusted publishing
77+
steps:
78+
- name: Download build artifacts
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: dist
82+
path: dist/
83+
84+
- name: Publish to PyPI
85+
uses: pypa/gh-action-pypi-publish@release/v1
86+
87+
# Create draft GitHub Release
88+
github-release:
89+
name: Create GitHub Release
90+
needs: publish-pypi
91+
runs-on: ubuntu-latest
92+
permissions:
93+
contents: write
94+
steps:
95+
- name: Checkout code
96+
uses: actions/checkout@v4
97+
98+
- name: Download build artifacts
99+
uses: actions/download-artifact@v4
100+
with:
101+
name: dist
102+
path: dist/
103+
104+
- name: Create draft release
105+
uses: softprops/action-gh-release@v2
106+
with:
107+
draft: true
108+
generate_release_notes: true
109+
files: dist/*

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,45 @@
22

33
All notable changes to TypeBridge will be documented in this file.
44

5+
## [1.2.7] - 2026-02-03
6+
7+
### New Features
8+
9+
#### TypeDB 3.8.0 Support (PR #93)
10+
- Full compatibility with TypeDB 3.8.0
11+
- Updated driver integration
12+
13+
### Performance Improvements
14+
15+
#### Batch Operations Optimization
16+
- **Batch delete operations** with disjunctive IID matching
17+
- **Batch entity inserts/puts** into single query
18+
- **Optimized IID retrieval** with single-query insert+fetch
19+
20+
### Bug Fixes
21+
22+
- **HydrationError handling** - Raise HydrationError instead of silently swallowing exceptions
23+
- **Variable collision prevention** - Use double underscore separator to prevent variable collisions
24+
- **TypeDB 3.x relation syntax** - Use correct relation insert syntax with `links` keyword
25+
- **Multi-variable let fix** - Remove incorrect parentheses in multi-variable let assignment
26+
- **Polymorphic attributes** - Restore polymorphic attribute fetching with nested wildcard
27+
28+
### Refactoring
29+
30+
- Consolidate duplicated code and fix Python 3.13 warnings
31+
- Unify entity identification logic across managers
32+
- Extract shared attribute-to-AST logic into TypeDBType
33+
- Remove `.c` accessor for direct field access
34+
35+
### Code Quality
36+
37+
- Remove all `type: ignore` comments for full type safety
38+
39+
### Testing
40+
41+
- Add recursive relation tests
42+
- Add validation performance benchmarks
43+
544
## [1.2.6] - 2026-02-01
645

746
### New Features

CLAUDE.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ uv run pyright tests/ # Type check tests
3939

4040
## Project Structure
4141

42-
```
42+
```text
4343
type_bridge/
4444
├── __init__.py # Main package exports
4545
├── query.py # TypeQL query builder
@@ -269,4 +269,65 @@ persons = person_manager.all()
269269
8. **Connection type** - Managers accept `Database`, `Transaction`, or `TransactionContext`
270270
9. **Dict helpers** - Use `to_dict()` and `from_dict()` for serialization
271271

272+
## Claude Code Instructions
273+
274+
### Always Fix Issues
275+
276+
**CRITICAL**: When encountering bugs, test failures, or issues during development:
277+
278+
- ALWAYS fix issues, regardless of whether they appear to be "pre-existing"
279+
- Never dismiss bugs as "not related to current changes" - if you found it, fix it
280+
- Complete the work fully; don't leave partial implementations
281+
- If a refactor is done, it should be COMPLETE - no dead code, no overridden methods that defeat the purpose
282+
283+
### Code Quality Standards
284+
285+
**CRITICAL: Always run checks on the ENTIRE codebase, not just modified files.**
286+
287+
AI sessions may include multiple separate conversations or context compactions, so changes from earlier in a session could introduce issues. Running checks on only a subset of files will miss these problems and cause CI failures.
288+
289+
Before committing, run ALL of these on the entire codebase:
290+
291+
```bash
292+
uv run ruff check --fix . # Lint entire codebase
293+
uv run ruff format . # Format entire codebase
294+
uv run pyright type_bridge/ # Type check library
295+
uv run pyright tests/ # Type check tests
296+
uv run pytest tests/unit/ -x # Run all unit tests
297+
```
298+
299+
Before PRs, also run:
300+
301+
```bash
302+
./test-integration.sh # Integration tests (requires TypeDB)
303+
```
304+
305+
Additional standards:
306+
307+
- When unifying code (e.g., EntityManager + RelationManager), remove ALL duplicated methods from subclasses
308+
- Delete dead code completely - no backwards-compatibility hacks, no `_unused` variables, no `# removed` comments
309+
310+
### Pydantic Best Practices
311+
312+
When working with Pydantic model validators:
313+
314+
- **Avoid `object.__setattr__`** - Using `object.__setattr__` to bypass Pydantic's validation is a hack that can mask bugs
315+
- **Use `mode='before'` validators** to transform input data BEFORE validation, avoiding recursion with `validate_assignment=True`
316+
- **Use `mode='wrap'` validators** only when you need to capture state before AND after validation (e.g., preserving private attributes)
317+
- **Access private attributes via `__pydantic_private__`** - This is Pydantic's official API for private attribute storage
318+
319+
Example pattern for value transformation:
320+
321+
```python
322+
@model_validator(mode="before")
323+
@classmethod
324+
def transform_input(cls, values: Any) -> dict[str, Any]:
325+
"""Transform input BEFORE validation - no recursion possible."""
326+
if isinstance(values, dict):
327+
data = dict(values)
328+
# Transform values here
329+
return data
330+
return values
331+
```
332+
272333
For detailed documentation, see the links above.

docs/INTERNALS.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class EntityManager(Generic[E]):
176176
```
177177

178178
**Benefits:**
179+
179180
- Cleaner syntax
180181
- Better IDE support
181182
- Matches modern Python standards
@@ -227,6 +228,7 @@ TypeBridge is fully compatible with:
227228
- **Pydantic's type system**: Built on Pydantic v2
228229

229230
**Current status:**
231+
230232
- ✅ 0 type errors with Pyright
231233
- ✅ 0 type warnings (except in type-check-except tests)
232234
- ✅ Full type inference for managers and queries
@@ -263,9 +265,7 @@ Tests that intentionally check Pydantic validation behavior use raw values and a
263265

264266
```json
265267
{
266-
"exclude": [
267-
"tests/unit/type-check-except/**"
268-
]
268+
"exclude": ["tests/unit/type-check-except/**"]
269269
}
270270
```
271271

@@ -278,19 +278,22 @@ The project minimizes `Any` usage for type safety:
278278
**Where `Any` is used:**
279279

280280
1. **`Flag()` function**: Accepts `Any` for parameters to handle type aliases like `Key` and `Unique`
281+
281282
```python
282283
def Flag(*args: Any) -> AttributeFlags:
283284
"""Create attribute flags from Key, Unique, Card arguments."""
284285
...
285286
```
286287

287288
2. **`Flag()` return type**: Returns `AttributeFlags` (used as field default)
289+
288290
```python
289291
class Person(Entity):
290292
name: Name = Flag(Key) # Flag() returns AttributeFlags
291293
```
292294

293295
3. **Pydantic core schema methods**: Use proper TypeVars (`StrValue`, `IntValue`, etc.)
296+
294297
```python
295298
@classmethod
296299
def __get_pydantic_core_schema__(
@@ -381,6 +384,7 @@ class Entity(BaseModel):
381384
```
382385

383386
This tells type checkers:
387+
384388
- All fields are keyword-only by default
385389
- `Flag()` is recognized as a valid field specifier
386390
- Constructor signature is inferred from class annotations
@@ -433,12 +437,11 @@ crud/
433437
### Import Patterns
434438

435439
```python
436-
# Public API (backward compatible)
437-
from type_bridge import EntityManager, RelationManager
440+
# Public API
441+
from type_bridge import TypeDBManager
438442

439-
# Direct module imports (new style)
440-
from type_bridge.crud.entity import EntityManager
441-
from type_bridge.crud.relation import RelationManager
443+
# Or from crud module
444+
from type_bridge.crud import TypeDBManager
442445

443446
# Shared utilities (internal use)
444447
from type_bridge.crud.utils import format_value, is_multi_value_attribute
@@ -482,6 +485,7 @@ with db.transaction(TransactionType.WRITE) as tx:
482485
```
483486

484487
**Behavior:**
488+
485489
- Auto-commit on successful context exit (WRITE/SCHEMA transactions)
486490
- Auto-rollback on exception
487491
- READ transactions never commit (no writes)
@@ -510,6 +514,7 @@ class ConnectionExecutor:
510514
```
511515

512516
**Design principles:**
517+
513518
1. **Transparency**: CRUD operations work identically regardless of connection type
514519
2. **Transaction reuse**: Existing transactions are never duplicated
515520
3. **Auto-management**: Database connections create transactions as needed

examples/advanced/schema_01_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
Key,
1919
Relation,
2020
Role,
21+
SchemaManager,
2122
String,
2223
TypeFlags,
2324
Unique,
2425
)
25-
from type_bridge.schema import SchemaManager
2626
from type_bridge.session import Database
2727

2828

examples/advanced/schema_02_comparison.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
Key,
1515
Relation,
1616
Role,
17+
SchemaManager,
1718
String,
1819
TypeFlags,
1920
)
20-
from type_bridge.schema import SchemaManager
2121

2222

2323
# Version 1: Initial schema

examples/advanced/schema_03_conflict.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
Entity,
99
Flag,
1010
Key,
11+
SchemaConflictError,
12+
SchemaManager,
1113
String,
1214
TypeFlags,
1315
)
14-
from type_bridge.schema import SchemaConflictError, SchemaManager
1516
from type_bridge.session import Database
1617

1718

0 commit comments

Comments
 (0)