# Buggy code
def _get_enabled(self, from_dict, default=None):
    """
    Retrieve the enabled state from the given dict of host variables.

    The enabled variable may be specified as 'foo.bar', in which case
    the lookup will traverse into nested dicts, equivalent to:

    from_dict.get('foo', {}).get('bar', default)
    """
    enabled = default
    if getattr(self, "enabled_var", None):
        default = object()
        for key in self.enabled_var.split("."):
            if not hasattr(from_dict, "get"):
                enabled = default
                break
            enabled = from_dict.get(key, default)
            from_dict = enabled
        if enabled is not default:
            enabled_value = getattr(self, "enabled_value", None)
            if enabled_value is not None:
                enabled = bool(unicode(enabled_value) == unicode(enabled))
            else:
                enabled = bool(enabled)
    return enabled


# Traceback (django.core.exceptions.ValidationError)
2017-11-23 01:44:04,433 INFO     awx.main.commands.inventory_import Updating inventory 2: CF
2017-11-23 01:44:04,472 INFO     awx.main.commands.inventory_import Reading Ansible inventory source: /usr/lib/python2.7/site-packages/awx/plugins/inventory/cloudforms.py
2017-11-23 01:44:34,698 INFO     awx.main.commands.inventory_import Processing JSON output...
2017-11-23 01:44:34,720 INFO     awx.main.commands.inventory_import Loaded 322 groups, 266 hosts
...
2017-11-23 01:44:34,739 WARNING  awx.main.commands.inventory_import Host \"<redacted1>\" has no \"id\" variable
2017-11-23 01:44:34,739 WARNING  awx.main.commands.inventory_import Host \"<redacted2>\" has no \"id\" variable
2017-11-23 01:44:34,739 WARNING  awx.main.commands.inventory_import Host \"<redacted3>\" has no \"id\" variable
...
2017-11-23 01:44:38,254 INFO     awx.main.commands.inventory_import Group \"<redacted4>_ovf\" added
2017-11-23 01:44:38,261 INFO     awx.main.commands.inventory_import Group \"<redacted5>_ovf\" added
2017-11-23 01:44:38,269 INFO     awx.main.commands.inventory_import Group \"location\" added
2017-11-23 01:44:38,276 INFO     awx.main.commands.inventory_import Group \"redhat\" added
2017-11-23 01:44:38,283 INFO     awx.main.commands.inventory_import Group \"tags\" added
2017-11-23 01:44:38,290 INFO     awx.main.commands.inventory_import Group \"type\" added
2017-11-23 01:44:38,298 INFO     awx.main.commands.inventory_import Group \"vendor\" added
Traceback (most recent call last):
File \"/usr/bin/awx-manage\", line 9, in <module>
load_entry_point('awx==1.0.1.225', 'console_scripts', 'awx-manage')()
File \"/usr/lib/python2.7/site-packages/awx/__init__.py\", line 109, in manage
execute_from_command_line(sys.argv)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py\", line 364, in execute_from_command_line
utility.execute()
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py\", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py\", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py\", line 330, in execute
output = self.handle(*args, **options)
File \"/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py\", line 1020, in handle
self.load_into_database()
File \"/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py\", line 892, in load_into_database
self._create_update_hosts()
File \"/usr/lib/python2.7/site-packages/awx/main/management/commands/inventory_import.py\", line 798, in _create_update_hosts
db_host = self.inventory.hosts.update_or_create(name=mem_host_name, defaults=host_attrs)[0]
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/fields/related_descriptors.py\", line 665, in update_or_create
return super(RelatedManager, self.db_manager(db)).update_or_create(**kwargs)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/manager.py\", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py\", line 482, in update_or_create
obj, created = self._create_object_from_params(lookup, params)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py\", line 498, in _create_object_from_params
obj = self.create(**params)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py\", line 394, in create
obj.save(force_insert=True, using=self.db)
File \"/usr/lib/python2.7/site-packages/awx/main/models/inventory.py\", line 665, in save
super(Host, self).save(*args, **kwargs)
File \"/usr/lib/python2.7/site-packages/awx/main/models/base.py\", line 264, in save
super(PrimordialModel, self).save(*args, **kwargs)
File \"/usr/lib/python2.7/site-packages/awx/main/models/base.py\", line 159, in save
super(CreatedModifiedModel, self).save(*args, **kwargs)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/base.py\", line 808, in save
force_update=force_update, update_fields=update_fields)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/base.py\", line 838, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/base.py\", line 924, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/base.py\", line 963, in _do_insert
using=using, raw=raw)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/manager.py\", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py\", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/sql/compiler.py\", line 1106, in execute_sql
for sql, params in self.as_sql():
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/sql/compiler.py\", line 1059, in as_sql
for obj in self.query.objs
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/sql/compiler.py\", line 998, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 770, in get_db_prep_save
prepared=False)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 762, in get_db_prep_value
value = self.get_prep_value(value)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 1043, in get_prep_value
return self.to_python(value)
File \"/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/fields/__init__.py\", line 1036, in to_python
params={'value': value},
django.core.exceptions.ValidationError: [u\"'<object object at 0x6aa0f40>' value must be either True or False.\"]

# Fixed code
def _get_enabled(self, from_dict, default=None):
    """
    Retrieve the enabled state from the given dict of host variables.

    The enabled variable may be specified as 'foo.bar', in which case
    the lookup will traverse into nested dicts, equivalent to:

    from_dict.get('foo', {}).get('bar', default)
    """
    enabled = default
    if getattr(self, "enabled_var", None):
        default = object()
        for key in self.enabled_var.split("."):
            if not hasattr(from_dict, "get"):
                enabled = default
                break
            enabled = from_dict.get(key, default)
            from_dict = enabled
        if enabled is not default:
            enabled_value = getattr(self, "enabled_value", None)
            if enabled_value is not None:
                enabled = bool(unicode(enabled_value) == unicode(enabled))
            else:
                enabled = bool(enabled)
    if enabled is default:
        return None
    elif isinstance(enabled, bool):
        return enabled
    else:
        raise NotImplementedError("Value of enabled {} not understood.".format(enabled))