Skip to content

Commit c57fb34

Browse files
FIX: Address review feedback - add workflows, anti-patterns, exception hierarchy
1 parent 098b028 commit c57fb34

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

.github/copilot-instructions.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@
1010
- **Python Versions**: 3.10+
1111
- **Key Dependencies**: pybind11, azure-identity, Microsoft ODBC Driver 18
1212

13+
## Development Workflows
14+
15+
This repository includes detailed prompt files for common tasks. Reference these with `#`:
16+
17+
| Task | Prompt | When to Use |
18+
|------|--------|-------------|
19+
| First-time setup | `#setup-dev-env` | New machine, fresh clone |
20+
| Build C++ extension | `#build-ddbc` | After modifying .cpp/.h files |
21+
| Run tests | `#run-tests` | Validating changes |
22+
| Create PR | `#create-pr` | Ready to submit changes |
23+
24+
**Workflow order for new contributors:**
25+
1. `#setup-dev-env` → Set up venv and dependencies
26+
2. `#build-ddbc` → Build native extension
27+
3. Make your changes
28+
4. `#run-tests` → Validate
29+
5. `#create-pr` → Submit
30+
1331
## Usage Examples (For Suggesting to Users)
1432

1533
### Basic Connection and Query
@@ -68,11 +86,13 @@ conn.commit()
6886

6987
### Transaction Handling
7088
```python
89+
from mssql_python import DatabaseError
90+
7191
try:
7292
cursor.execute("UPDATE accounts SET balance = balance - 100 WHERE id = ?", (from_id,))
7393
cursor.execute("UPDATE accounts SET balance = balance + 100 WHERE id = ?", (to_id,))
7494
conn.commit()
75-
except Exception:
95+
except DatabaseError:
7696
conn.rollback()
7797
raise
7898
```
@@ -234,6 +254,55 @@ The `ddbc_bindings.py` module implements sophisticated architecture detection:
234254
- **macOS**: Runtime architecture detection, always loads from universal2 binary
235255
- **Linux**: Maps `x64/amd64``x86_64`, `arm64/aarch64``arm64`
236256

257+
## Exception Hierarchy
258+
259+
Critical for error handling guidance:
260+
261+
```
262+
Error (base)
263+
├── DatabaseError
264+
│ ├── InterfaceError # Driver/interface issues
265+
│ ├── OperationalError # Connection/timeout issues
266+
│ ├── IntegrityError # Constraint violations
267+
│ ├── ProgrammingError # SQL syntax errors
268+
│ └── DataError # Invalid data processing
269+
└── Warning
270+
```
271+
272+
## Critical Anti-Patterns (DO NOT)
273+
274+
- **NEVER** hardcode connection strings - always use `DB_CONNECTION_STRING` env var for tests
275+
- **NEVER** use `pyodbc` imports - this driver doesn't require external ODBC
276+
- **NEVER** modify files in `mssql_python/libs/` - these are pre-built binaries
277+
- **NEVER** skip `conn.commit()` after INSERT/UPDATE/DELETE operations
278+
- **NEVER** use bare `except:` blocks - always catch specific exceptions
279+
- **NEVER** leave connections open - use context managers or explicit `close()`
280+
281+
## When Modifying Code
282+
283+
### Python Changes
284+
- Preserve existing error handling patterns from `exceptions.py`
285+
- Use context managers (`with`) for all connection/cursor operations
286+
- Update `__all__` exports if adding public API
287+
- Add corresponding test in `tests/test_*.py`
288+
- Follow Black formatting (line length 100)
289+
290+
### C++ Changes
291+
- Follow RAII patterns for resource management
292+
- Use `py::gil_scoped_release` for blocking ODBC operations
293+
- Update `mssql_python.pyi` type stubs if changing Python API
294+
- Follow `.clang-format` style (Google style, 100 column limit)
295+
296+
## Debugging Quick Reference
297+
298+
| Error | Cause | Solution |
299+
|-------|-------|----------|
300+
| `ImportError: ddbc_bindings` | Extension not built | Run `#build-ddbc` |
301+
| Connection timeout | Missing env var | Set `DB_CONNECTION_STRING` |
302+
| `dylib not found` (macOS) | Library paths | Run `configure_dylibs.sh` |
303+
| `ODBC Driver not found` | Missing driver | Install Microsoft ODBC Driver 18 |
304+
| `ModuleNotFoundError` | Not in venv | Run `#setup-dev-env` |
305+
237306
## Contributing Guidelines
238307

239308
### PR Requirements

0 commit comments

Comments
 (0)