Skip to content

Conversation

shnizzedy
Copy link
Member

Fixes

Fixes

C-PAC failed to start
Traceback (most recent call last):
  File "/code/CPAC/pipeline/cpac_runner.py", line 652, in run
    exitcode = run_workflow(
  File "/code/CPAC/pipeline/cpac_pipeline.py", line 806, in run_workflow
    resource_report(cb_log_filename, num_cores_per_sub, WFLOGGER)
  File "/code/CPAC/utils/monitoring/draw_gantt_chart.py", line 598, in resource_report
    generate_gantt_chart(callback_log, num_cores)
  File "/code/CPAC/utils/monitoring/draw_gantt_chart.py", line 419, in generate_gantt_chart
    events = create_event_dict(start_node["start"], nodes_list)
  File "/code/CPAC/utils/monitoring/draw_gantt_chart.py", line 93, in create_event_dict
    finish_node = copy.deepcopy(node)
  File "/usr/share/fsl/6.0/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/share/fsl/6.0/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/share/fsl/6.0/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/share/fsl/6.0/lib/python3.10/copy.py", line 265, in _reconstruct
    y = func(*args)
  File "/code/CPAC/utils/monitoring/monitoring.py", line 111, in __new__
    raise TypeError(error)
TypeError: Cannot convert <class 'bytes'> to datetime

Technical details

UnicodeDecodeError was the wrong exception to catch; this updates it to (struct.error, IndexError) and adds tests.

Tests

def test_deepcopy_datetimewithsafenone_raises_error() -> None:
"""Test bytestring TypeError during deepcopy operation."""
# Create a node dictionary similar to what's used in the Gantt chart generation
node = {
"id": "test_node",
"hash": "abc123",
"start": DatetimeWithSafeNone(
datetime(2024, 1, 1, 10, 0, 0, tzinfo=timezone.utc)
),
"finish": DatetimeWithSafeNone(
datetime(2024, 1, 1, 11, 30, 0, tzinfo=timezone.utc)
),
"runtime_threads": 4,
"runtime_memory_gb": 2.5,
"estimated_memory_gb": 3.0,
"num_threads": 4,
}
# This should raise: TypeError: Cannot convert <class 'bytes'> to datetime
# with the original code because deepcopy pickles DatetimeWithSafeNone objects
# as bytes, and the __new__ method doesn't properly handle the pickle protocol
finish_node = deepcopy(node)
assert finish_node["start"] == node["start"]
assert finish_node["finish"] == node["finish"]
def test_deepcopy_datetimewithsafenone_direct():
"""Test deepcopy directly on DatetimeWithSafeNone instance."""
dt = DatetimeWithSafeNone(datetime(2024, 1, 1, 10, 0, 0, tzinfo=timezone.utc))
# This triggers the pickle/unpickle cycle which passes bytes to __new__
dt_copy = deepcopy(dt)
assert dt_copy == dt
assert isinstance(dt_copy, DatetimeWithSafeNone)

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the develop branch of the repository.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I updated the changelog.
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@shnizzedy shnizzedy requested a review from a team as a code owner October 9, 2025 19:22
@shnizzedy shnizzedy self-assigned this Oct 9, 2025
@shnizzedy shnizzedy added the bug label Oct 9, 2025
@shnizzedy shnizzedy moved this to 👀 In review in C-PAC Development Oct 9, 2025
@shnizzedy shnizzedy added this to the 1.8.8 release milestone Oct 9, 2025
@shnizzedy shnizzedy added develop issue on `develop` branch logging labels Oct 9, 2025
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 47.22222% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.9%. Comparing base (8dfdd9e) to head (2ab43b1).

Files with missing lines Patch % Lines
CPAC/utils/monitoring/monitoring.py 20.8% 14 Missing and 5 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2290   +/-   ##
=======================================
  Coverage     34.9%   34.9%           
=======================================
  Files          234     234           
  Lines        26632   26661   +29     
  Branches      4184    4190    +6     
=======================================
+ Hits          9291    9305   +14     
- Misses       16602   16611    +9     
- Partials       739     745    +6     
Files with missing lines Coverage Δ
CPAC/utils/tests/test_utils.py 97.9% <100.0%> (+0.3%) ⬆️
CPAC/utils/monitoring/monitoring.py 40.4% <20.8%> (-1.9%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug develop issue on `develop` branch logging

Projects

Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

1 participant