Files
TimeTracker/docs/implementation-notes/BUGFIX_METADATA_RESERVED.md
T
Dries Peeters 29f7186ee8 docs: Reorganize documentation structure for better navigation
Complete reorganization of project documentation to improve discoverability,
navigation, and maintainability. All documentation has been restructured into
a clear, role-based hierarchy.

## Major Changes

### New Directory Structure
- Created `docs/api/` for API documentation
- Created `docs/admin/` with subdirectories:
  - `admin/configuration/` - Configuration guides
  - `admin/deployment/` - Deployment guides
  - `admin/security/` - Security documentation
  - `admin/monitoring/` - Monitoring and analytics
- Created `docs/development/` for developer documentation
- Created `docs/guides/` for user-facing guides
- Created `docs/reports/` for analysis reports and summaries
- Created `docs/changelog/` for detailed changelog entries (ready for future use)

### File Organization

#### Moved from Root Directory (40+ files)
- Implementation notes → `docs/implementation-notes/`
- Test reports → `docs/testing/`
- Analysis reports → `docs/reports/`
- User guides → `docs/guides/`

#### Reorganized within docs/
- API documentation → `docs/api/`
- Administrator documentation → `docs/admin/` (with subdirectories)
- Developer documentation → `docs/development/`
- Security documentation → `docs/admin/security/`
- Telemetry documentation → `docs/admin/monitoring/`

### Documentation Updates

#### docs/README.md
- Complete rewrite with improved navigation
- Added visual documentation map
- Organized by role (Users, Administrators, Developers)
- Better categorization and quick links
- Updated all internal links to new structure

#### README.md (root)
- Updated all documentation links to reflect new structure
- Fixed 8 broken links

#### app/templates/main/help.html
- Enhanced "Where can I get additional help?" section
- Added links to new documentation structure
- Added documentation index link
- Added admin documentation link for administrators
- Improved footer with organized documentation links
- Added "Complete Documentation" section with role-based links

### New Index Files
- Created README.md files for all new directories:
  - `docs/api/README.md`
  - `docs/guides/README.md`
  - `docs/reports/README.md`
  - `docs/development/README.md`
  - `docs/admin/README.md`

### Cleanup
- Removed empty `docs/security/` directory (moved to `admin/security/`)
- Removed empty `docs/telemetry/` directory (moved to `admin/monitoring/`)
- Root directory now only contains: README.md, CHANGELOG.md, LICENSE

## Results

**Before:**
- 45+ markdown files cluttering root directory
- Documentation scattered across root and docs/
- Difficult to find relevant documentation
- No clear organization structure

**After:**
- 3 files in root directory (README, CHANGELOG, LICENSE)
- Clear directory structure organized by purpose and audience
- Easy navigation with role-based organization
- All documentation properly categorized
- Improved discoverability

## Benefits

1. Better Organization - Documentation grouped by purpose and audience
2. Easier Navigation - Role-based sections (Users, Admins, Developers)
3. Improved Discoverability - Clear structure with README files in each directory
4. Cleaner Root - Only essential files at project root
5. Maintainability - Easier to add and organize new documentation

## Files Changed

- 40+ files moved from root to appropriate docs/ subdirectories
- 15+ files reorganized within docs/
- 3 major documentation files updated (docs/README.md, README.md, help.html)
- 5 new README index files created
- 2 empty directories removed

All internal links have been updated to reflect the new structure.
2025-12-14 07:56:07 +01:00

3.2 KiB

🐛 Bug Fix: SQLAlchemy Reserved Name 'metadata'

Issue

Error:

sqlalchemy.exc.InvalidRequestError: Attribute name 'metadata' is reserved when using the Declarative API.

Cause: The Activity model used metadata as a column name, which is a reserved attribute in SQLAlchemy's Declarative API. SQLAlchemy uses metadata internally for managing table metadata.


🔧 Fix Applied

Changed Files (3)

1. app/models/activity.py

Changed: Renamed column from metadata to extra_data

# Before
metadata = db.Column(db.JSON, nullable=True)

# After
extra_data = db.Column(db.JSON, nullable=True)

Backward Compatibility: The log() class method now accepts both parameters:

  • extra_data (new, preferred)
  • metadata (deprecated, for compatibility)
@classmethod
def log(cls, ..., extra_data=None, metadata=None, ...):
    # Support both parameter names
    data = extra_data if extra_data is not None else metadata
    activity = cls(..., extra_data=data, ...)

The to_dict() method returns both keys for compatibility:

{
    'extra_data': self.extra_data,
    'metadata': self.extra_data,  # For backward compatibility
}

2. migrations/versions/add_quick_wins_features.py

Changed: Column name in migration

# Before
sa.Column('metadata', sa.JSON(), nullable=True),

# After
sa.Column('extra_data', sa.JSON(), nullable=True),

3. app/routes/time_entry_templates.py

Changed: Updated Activity.log call

# Before
Activity.log(..., metadata={'old_name': old_name}, ...)

# After
Activity.log(..., extra_data={'old_name': old_name}, ...)

Verification

Linter Check

✅ No linter errors found

Syntax Check

python -m py_compile app/models/activity.py
python -m py_compile app/routes/time_entry_templates.py
python -m py_compile migrations/versions/add_quick_wins_features.py

✅ All files compile successfully

🚀 Next Steps

The application should now start successfully. Run:

docker-compose restart app

Or if you need to apply the migration:

flask db upgrade
docker-compose restart app

📝 Notes

Backward Compatibility

The Activity.log() method maintains backward compatibility by accepting both metadata and extra_data parameters. This means:

  • Old code using metadata=... will continue to work
  • New code should use extra_data=...
  • No breaking changes to existing code

Database Column

The actual database column is now named extra_data. If you have any existing activities in the database, they will need to be migrated (but since this is a new feature, there shouldn't be any existing data).

API Responses

The to_dict() method returns both extra_data and metadata keys in the JSON response for maximum compatibility with any frontend code.


🎯 Summary

Problem: Used SQLAlchemy reserved name metadata
Solution: Renamed to extra_data with backward compatibility
Impact: Zero breaking changes, fully backward compatible
Status: Fixed and verified


Date: 2025-10-23
Type: Bug Fix
Severity: Critical (prevented startup)
Resolution Time: < 5 minutes