Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_maintenance crashes on empty report #55

Open
rohanpm opened this issue Sep 23, 2019 · 0 comments
Open

set_maintenance crashes on empty report #55

rohanpm opened this issue Sep 23, 2019 · 0 comments

Comments

@rohanpm
Copy link
Member

rohanpm commented Sep 23, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant