# Buggy code
def get_resource_date(self, asg):
    cfg = self.launch_info.get(asg)
    ami = self.images.get(cfg.get("ImageId"), {})
    return parse(ami.get(self.date_attribute, "2000-01-01T01:01:01.000Z"))


# Traceback (AttributeError)
custodian run --dryrun --profile abc asg-ami.yml --region us-east-1 -s asg-ami --cache-period 0 -v
2020-05-11 16:26:37,495: custodian.cache:DEBUG Disabling cache
2020-05-11 16:26:37,496: custodian.commands:DEBUG Loaded file asg-ami.yml. Contains 1 policies
2020-05-11 16:26:38,023: custodian.output:DEBUG Storing output with <LogFile asg-ami/custodian-run.log>
2020-05-11 16:26:38,165: custodian.policy:DEBUG Running policy:asg-ami
resource:asg region:us-east-1 c7n:0.9.1
2020-05-11 16:26:51,425: custodian.resources.launchconfig:DEBUG Filtered from 527 to 527 launchconfig
2020-05-11 16:26:51,683: custodian.output:DEBUG metric:PolicyException Count:1 policy:asg-ami
restype:asg
2020-05-11 16:26:51,683: custodian.output:DEBUG metric:ApiCalls Count:28 policy:asg-ami
restype:asg
2020-05-11 16:26:51,683: custodian.output:ERROR Error while executing policy
Traceback (most recent call last):
File "/Users/abc/custodian/cloud-custodian/c7n/policy.py", line 291, in run
resources = self.policy.resource_manager.resources()
File "/Users/abc/custodian/cloud-custodian/c7n/query.py", line 465, in resources
resources = self.filter_resources(resources)
File "/Users/abc/custodian/cloud-custodian/c7n/manager.py", line 109, in filter_resources
resources = f.process(resources, event)
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 258, in process
return self.process_set(resources, event)
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 274, in process_set
r[rtype_id] for r in f.process(resources, event)])
File "/Users/abc/custodian/cloud-custodian/c7n/resources/asg.py", line 573, in process
return super(ImageAgeFilter, self).process(asgs, event)
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 197, in process
return list(filter(self, resources))
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 677, in __call__
v = self.get_resource_date(i)
File "/Users/abc/custodian/cloud-custodian/c7n/resources/asg.py", line 577, in get_resource_date
ami = self.images.get(cfg.get('ImageId'), {})
AttributeError: 'NoneType' object has no attribute 'get'
2020-05-11 16:26:51,688: custodian.commands:ERROR Error while executing policy asg-ami, continuing
Traceback (most recent call last):
File "/Users/abc/custodian/cloud-custodian/c7n/commands.py", line 281, in run
policy()
File "/Users/abc/custodian/cloud-custodian/c7n/policy.py", line 1031, in __call__
resources = PullMode(self).run()
File "/Users/abc/custodian/cloud-custodian/c7n/policy.py", line 291, in run
resources = self.policy.resource_manager.resources()
File "/Users/abc/custodian/cloud-custodian/c7n/query.py", line 465, in resources
resources = self.filter_resources(resources)
File "/Users/abc/custodian/cloud-custodian/c7n/manager.py", line 109, in filter_resources
resources = f.process(resources, event)
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 258, in process
return self.process_set(resources, event)
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 274, in process_set
r[rtype_id] for r in f.process(resources, event)])
File "/Users/abc/custodian/cloud-custodian/c7n/resources/asg.py", line 573, in process
return super(ImageAgeFilter, self).process(asgs, event)
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 197, in process
return list(filter(self, resources))
File "/Users/abc/custodian/cloud-custodian/c7n/filters/core.py", line 677, in __call__
v = self.get_resource_date(i)
File "/Users/abc/custodian/cloud-custodian/c7n/resources/asg.py", line 577, in get_resource_date
ami = self.images.get(cfg.get('ImageId'), {})
AttributeError: 'NoneType' object has no attribute 'get'

# Fixed code
def get_resource_date(self, asg):
    cfg = self.launch_info.get(asg)
    if cfg is None:
        cfg = {}
    ami = self.images.get(cfg.get("ImageId"), {})
    return parse(ami.get(self.date_attribute, "2000-01-01T01:01:01.000Z"))