PYTHON PACKAGE HOOK FAILURES

Bug #2127755 reported by Helmut Zollner
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python3.12 (Ubuntu)
New
Undecided
Unassigned

Bug Description

Hi!

I had to reainstall my system today because I got load of errors during installation of new applications with apt.

Apparently they were cause by some hooks that didn't quite work.

i used Deepseek to help me with this installation and I spent the better part of the entire weekend trying to get it working.

Here is the very detailed bug report. I had searched the bug database for the headline of this report, but could not find one. Maybe I didn't enter the right keywords.

Anyway, it is my first post of a bug. I apologize for any formal errors I am making in reporting this, but I thpught this ecperience was painful enough the be shared to avoid someone else falling into the same trap.

Funnily enough the system was fully functional. despite reporting loads of errors during installation.

So, in the end we disabled all the debian hooks and the system reports it is working fine.

I am running this on a newly installed Mint Linux 22.2 system on an AMD64 platform with Python 3.12. I want to use the system to develop some application software and am very nervios to start with a compromised system.

So here we go.

📋 **COMPREHENSIVE BUG REPORT - PYTHON PACKAGE HOOK FAILURES**

## 🐛 **BUG REPORT TEMPLATE**

**Title:** `py3clean`/`py3compile` hooks fail with `AttributeError` when `debpython.files` module is corrupted or missing required methods

**Description:**
During system recovery from package management failures, the Python package post-installation hooks (`py3clean` and `py3compile`) fail catastrophically when the `debpython.files` module is missing expected methods, leading to a cascade of package configuration failures that can render the system unable to install or update packages.

**Steps to Reproduce:**
1. Corrupt or remove the `/usr/share/python3/debpython/files.py` module
2. Attempt to install or reconfigure any Python package (e.g., `sudo apt install python3`)
3. Observe `AttributeError` failures in package post-installation hooks

**Expected Behavior:**
Package hooks should handle missing or corrupted `debpython.files` methods gracefully, either by:
- Falling back to safe defaults
- Providing clear error messages
- Skipping non-critical operations
- Allowing package configuration to complete

**Actual Behavior:**
```python
Traceback (most recent call last):
  File "/usr/bin/py3compile", line 323, in <module>
    main()
  File "/usr/bin/py3compile", line 293, in main
    files = dpf.filter_directory(pkg_files, item)
            ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'debpython.files' has no attribute 'filter_directory'
```

**Impact:**
- Package management becomes unusable
- System cannot install security updates
- Recovery requires manual intervention or system reinstallation
- Affects all Python package installations

**Proposed Solutions:**
1. **Add graceful fallbacks** in `py3clean`/`py3compile` when methods are missing
2. **Implement method existence checks** before calling debpython functions
3. **Create a minimal safe implementation** that's used when the main module fails to load
4. **Better error handling** that doesn't block package configuration

**Where to Report:**

### **Primary (Ubuntu):**
```bash
# Ubuntu packages these tools
ubuntu-bug python3.12
# Or via web: https://bugs.launchpad.net/ubuntu/+source/python3.12
```

### **Secondary (Debian):**
```bash
# Debian is upstream for these tools
reportbug python3.12
# Or via web: https://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=python3.12
```

### **Specific Components:**
- **python3-defaults** package: https://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=python3-defaults
- **debpython** module: Part of python3-defaults

## 🔧 **TECHNICAL DETAILS FOR BUG REPORT:**

**Affected Packages:**
- `python3-defaults` (contains debpython module)
- `python3.X` (any Python 3 version)
- All Python-dependent packages

**Error Sequence:**
1. `py3clean` fails → `py3compile` fails → package configuration fails
2. Dependency chain breaks → multiple packages marked "half-configured"
3. System enters unrecoverable state without manual intervention

**Root Cause:**
The hooks assume `debpython.files` module is always fully functional and don't handle cases where:
- Module is missing
- Required methods are absent
- Module fails to import
- Methods raise exceptions

## 📝 **ADDITIONAL CONTEXT FOR DEVELOPERS:**

```markdown
During system recovery scenarios (common after failed upgrades or disk issues),
the debpython.files module can become corrupted or incomplete. The current
implementation has no fallback mechanism, causing complete failure of Python
package management.

This is particularly problematic because:
1. It prevents system recovery using standard package tools
2. Requires users to manually hack system files to regain functionality
3. Affects security updates and critical system maintenance
4. Has no clear recovery path for non-technical users

Suggested implementation would be to wrap debpython calls in try-catch blocks
and provide minimal fallback behavior when the module is unavailable.
```

## 🚀 **HOW TO SUBMIT:**

### **Command Line (Recommended):**
```bash
# Install reporting tool
sudo apt install apport

# Report bug for python3.12
ubuntu-bug python3.12

# Or for python3-defaults
ubuntu-bug python3-defaults
```

### **Web Interface:**
1. Go to: https://bugs.launchpad.net/ubuntu/+source/python3.12
2. Click "Report a Bug"
3. Use the template above

## 💡 **ADDITIONAL NOTES FOR THE REPORT:**

- **Mention this affects recovery scenarios** specifically
- **Reference the cascade failure** pattern
- **Suggest the nuclear option** (disabling hooks) should not be necessary
- **Emphasize the security implications** (cannot install updates)

**This bug effectively bricks package management** in recovery scenarios, making it a **high-priority** issue for system stability and security.

**Thank you for reporting this!** Your persistence in debugging this issue will help prevent others from experiencing the same system-breaking problem. 🛡️COMPREHENSIVE BUG REPORT - PYTHON PACKAGE HOOK FAILURES
🐛 BUG REPORT TEMPLATE
Title: py3clean/py3compile hooks fail with AttributeError when debpython.files module is corrupted or missing required methods
Description:
During system recovery from package management failures, the Python package post-installation hooks (py3clean and py3compile) fail catastrophically when the debpython.files module is missing expected methods, leading to a cascade of package configuration failures that can render the system unable to install or update packages.
Steps to Reproduce:
    1. Corrupt or remove the /usr/share/python3/debpython/files.py module
    2. Attempt to install or reconfigure any Python package (e.g., sudo apt install python3)
    3. Observe AttributeError failures in package post-installation hooks
Expected Behavior:
Package hooks should handle missing or corrupted debpython.files methods gracefully, either by:
    • Falling back to safe defaults
    • Providing clear error messages
    • Skipping non-critical operations
    • Allowing package configuration to complete
Actual Behavior:
python
Traceback (most recent call last):
  File "/usr/bin/py3compile", line 323, in <module>
    main()
  File "/usr/bin/py3compile", line 293, in main
    files = dpf.filter_directory(pkg_files, item)
            ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'debpython.files' has no attribute 'filter_directory'
Impact:
    • Package management becomes unusable
    • System cannot install security updates
    • Recovery requires manual intervention or system reinstallation
    • Affects all Python package installations
Proposed Solutions:
    1. Add graceful fallbacks in py3clean/py3compile when methods are missing
    2. Implement method existence checks before calling debpython functions
    3. Create a minimal safe implementation that's used when the main module fails to load
    4. Better error handling that doesn't block package configuration
Where to Report:
Primary (Ubuntu):
bash
# Ubuntu packages these tools
ubuntu-bug python3.12
# Or via web: https://bugs.launchpad.net/ubuntu/+source/python3.12
Secondary (Debian):
bash
# Debian is upstream for these tools
reportbug python3.12
# Or via web: https://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=python3.12
Specific Components:
    • python3-defaults package: https://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=python3-defaults
    • debpython module: Part of python3-defaults
🔧 TECHNICAL DETAILS FOR BUG REPORT:
Affected Packages:
    • python3-defaults (contains debpython module)
    • python3.X (any Python 3 version)
    • All Python-dependent packages
Error Sequence:
    1. py3clean fails → py3compile fails → package configuration fails
    2. Dependency chain breaks → multiple packages marked "half-configured"
    3. System enters unrecoverable state without manual intervention
Root Cause:
The hooks assume debpython.files module is always fully functional and don't handle cases where:
    • Module is missing
    • Required methods are absent
    • Module fails to import
    • Methods raise exceptions
📝 ADDITIONAL CONTEXT FOR DEVELOPERS:
markdown
During system recovery scenarios (common after failed upgrades or disk issues),
the debpython.files module can become corrupted or incomplete. The current
implementation has no fallback mechanism, causing complete failure of Python
package management.

This is particularly problematic because:
1. It prevents system recovery using standard package tools
2. Requires users to manually hack system files to regain functionality
3. Affects security updates and critical system maintenance
4. Has no clear recovery path for non-technical users

Suggested implementation would be to wrap debpython calls in try-catch blocks
and provide minimal fallback behavior when the module is unavailable.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.