Hello
I'm having an issue with asserting that an instance of my custom Report
class is actually an instance of the class. I have a module where I declare a Report
and ReportDAO
class. In the ReportDAO
class I have an update
function which takes a Report
instance and modifies it, but first I want to assert that the passed report is the correct object type.
simplified:
class Report(object):
uuid = None
def __init__(self, uuid):
self.uuid = uuid or str(uuid_module.uuid1())
class ReportDAO(object):
"""
Data access for Report objects
"""
def update(self, report):
"""
Update a single report record
"""
assert_is_report(report)
# updates go here
The assert_is_report
just does an issubclass
check under the hood but it is failing when passing a report object. I added a bunch of logging to the update function and get the following log results:
def update(self, report):
"""
Update a single report record
"""
log.info("report.__class__: {}".format(report.__class__))
log.info("type(report): {}".format(type(report)))
log.info("Report: {}".format(Report))
log.info(
"issubclass(type(report), Report): {}".format(
issubclass(type(report), Report)
)
)
log.info("isinstance(report,Report): {}".format(isinstance(report, Report)))
log.info("type(report) is Report: {}".format(type(report) is Report))
new_report = Report(None, None, None)
log.info("new_report.__class__: {}".format(new_report.__class__))
log.info("type(new_report): {}".format(type(new_report)))
log.info("Report: {}".format(Report))
log.info(
"issubclass(type(new_report), Report): {}".format(
issubclass(type(new_report), Report)
)
)
log.info(
"isinstance(new_report,Report): {}".format(isinstance(new_report, Report))
)
log.info("type(new_report) is Report: {}".format(type(new_report) is Report))
why is my report instance that is passed to the update function not being recognised as an instance of Report
class?
for additional context, the report instance has been saved to and then retrieved from a list at system.util.getGlobals["reports"]
, and the saving and retrieving is being done by two different projects, that both import the Report
and ReportDAO
classes directly