Skip to content

set_maintenance crashes on empty report #55

@rohanpm

Description

@rohanpm

Summary

The set_maintenance method raises an exception if passed a default-constructed maintenance report.

Issue Type

  • Bug Report

Steps to reproduce

Try to set_maintenance with an empty MaintenanceReport. (Note: it can be reproduced with both real and fake clients, so no running Pulp server is needed)

>>> from pubtools.pulplib import FakeController, MaintenanceReport
>>> FakeController().client.set_maintenance(MaintenanceReport()).result()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rmcgover/src/pubtools-pulplib/pubtools/pulplib/_impl/fake/client.py", line 151, in set_maintenance
    report_json = json.dumps(report._export_dict(), indent=4, sort_keys=True)
  File "/home/rmcgover/src/pubtools-pulplib/pubtools/pulplib/_impl/model/maintenance.py", line 124, in _export_dict
    "last_updated": write_timestamp(self.last_updated),
  File "/home/rmcgover/src/pubtools-pulplib/pubtools/pulplib/_impl/model/convert.py", line 35, in write_timestamp
    return value.strftime("%Y-%m-%dT%H:%M:%SZ")
AttributeError: 'NoneType' object has no attribute 'strftime'

Actual results

Crashes with internal error.

Expected results

Two alternatives:

  1. (Preferred) the maintenance report is successfully uploaded, with last_updated field automatically initialized to the current date/time.
  2. The maintenance report is considered invalid, and an exception is raised with a meaningful type & message.

OS / Environment

all

Additional Information

It should not be solved by setting a default last_updated on the MaintenanceReport model, because that means two default-constructed MaintenanceReport aren't equal. It should probably be solved by having a default last_updated during the serialization to dict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions