The below sqlalchemy query def _query_filter_service_subnets(self, query, service_type): ServiceType = sst_model.SubnetServiceType query = query.add_entity(ServiceType) query = query.outerjoin(ServiceType) query = query.filter(or_(ServiceType.service_type.is_(None), ServiceType.service_type == service_type)) will translate to the following sql code in sqlite(while running UT test_create_port_no_device_owner_no_fallback) 2016-09-30 18:41:34,235 INFO sqlalchemy.engine.base.Engine.sqlite@ptzpgjyreu SELECT subnets.project_id AS subnets_project_id, subnets.id AS subnets_id, subnets.name AS subnets_name, subnets.network_id AS subnets_network_id, subnets.segment_id AS subnets_segment_id, subnets.subnetpool_id AS subnets_subnetpool_id, subnets.ip_version AS subnets_ip_version, subnets.cidr AS subnets_cidr, subnets.gateway_ip AS subnets_gateway_ip, subnets.enable_dhcp AS subnets_enable_dhcp, subnets.ipv6_ra_mode AS subnets_ipv6_ra_mode, subnets.ipv6_address_mode AS subnets_ipv6_address_mode, subnets.standard_attr_id AS subnets_standard_attr_id, subnet_service_types.subnet_id AS subnet_service_types_subnet_id, subnet_service_types.service_type AS subnet_service_types_service_type, subnetpoolprefixes_1.cidr AS subnetpoolprefixes_1_cidr, subnetpoolprefixes_1.subnetpool_id AS subnetpoolprefixes_1_subnetpool_id, standardattributes_1.id AS standardattributes_1_id, standardattributes_1.resource_type AS standardattributes_1_resource_type, standardattributes_1.description AS standardattributes_1_description, standardattributes_1.revision_number AS standardattributes_1_revision_number, standardattributes_1.created_at AS standardattributes_1_created_at, standardattributes_1.updated_at AS standardattributes_1_updated_at, tags_1.standard_attr_id AS tags_1_standard_attr_id, tags_1.tag AS tags_1_tag, subnetpools_1.project_id AS subnetpools_1_project_id, subnetpools_1.id AS subnetpools_1_id, subnetpools_1.name AS subnetpools_1_name, subnetpools_1.ip_version AS subnetpools_1_ip_version, subnetpools_1.default_prefixlen AS subnetpools_1_default_prefixlen, subnetpools_1.min_prefixlen AS subnetpools_1_min_prefixlen, subnetpools_1.max_prefixlen AS subnetpools_1_max_prefixlen, subnetpools_1.shared AS subnetpools_1_shared, subnetpools_1.is_default AS subnetpools_1_is_default, subnetpools_1.default_quota AS subnetpools_1_default_quota, subnetpools_1.hash AS subnetpools_1_hash, subnetpools_1.address_scope_id AS subnetpools_1_address_scope_id, subnetpools_1.standard_attr_id AS subnetpools_1_standard_attr_id, ipallocationpools_1.id AS ipallocationpools_1_id, ipallocationpools_1.subnet_id AS ipallocationpools_1_subnet_id, ipallocationpools_1.first_ip AS ipallocationpools_1_first_ip, ipallocationpools_1.last_ip AS ipallocationpools_1_last_ip, dnsnameservers_1.address AS dnsnameservers_1_address, dnsnameservers_1.subnet_id AS dnsnameservers_1_subnet_id, dnsnameservers_1."order" AS dnsnameservers_1_order, subnetroutes_1.destination AS subnetroutes_1_destination, subnetroutes_1.nexthop AS subnetroutes_1_nexthop, subnetroutes_1.subnet_id AS subnetroutes_1_subnet_id, networkrbacs_1.project_id AS networkrbacs_1_project_id, networkrbacs_1.id AS networkrbacs_1_id, networkrbacs_1.target_tenant AS networkrbacs_1_target_tenant, networkrbacs_1.action AS networkrbacs_1_action, networkrbacs_1.object_id AS networkrbacs_1_object_id, standardattributes_2.id AS standardattributes_2_id, standardattributes_2.resource_type AS standardattributes_2_resource_type, standardattributes_2.description AS standardattributes_2_description, standardattributes_2.revision_number AS standardattributes_2_revision_number, standardattributes_2.created_at AS standardattributes_2_created_at, standardattributes_2.updated_at AS standardattributes_2_updated_at, tags_2.standard_attr_id AS tags_2_standard_attr_id, tags_2.tag AS tags_2_tag, subnet_service_types_1.subnet_id AS subnet_service_types_1_subnet_id, subnet_service_types_1.service_type AS subnet_service_types_1_service_type, networkrbacs_2.project_id AS networkrbacs_2_project_id, networkrbacs_2.id AS networkrbacs_2_id, networkrbacs_2.target_tenant AS networkrbacs_2_target_tenant, networkrbacs_2.action AS networkrbacs_2_action, networkrbacs_2.object_id AS networkrbacs_2_object_id, anon_1.agents_1_id AS agents_1_id, anon_1.agents_1_agent_type AS agents_1_agent_type, anon_1.agents_1_binary AS agents_1_binary, anon_1.agents_1_topic AS agents_1_topic, anon_1.agents_1_host AS agents_1_host, anon_1.agents_1_availability_zone AS agents_1_availability_zone, anon_1.agents_1_admin_state_up AS agents_1_admin_state_up, anon_1.agents_1_created_at AS agents_1_created_at, anon_1.agents_1_started_at AS agents_1_started_at, anon_1.agents_1_heartbeat_timestamp AS agents_1_heartbeat_timestamp, anon_1.agents_1_description AS agents_1_description, anon_1.agents_1_configurations AS agents_1_configurations, anon_1.agents_1_resource_versions AS agents_1_resource_versions, anon_1.agents_1_load AS agents_1_load, standardattributes_3.id AS standardattributes_3_id, standardattributes_3.resource_type AS standardattributes_3_resource_type, standardattributes_3.description AS standardattributes_3_description, standardattributes_3.revision_number AS standardattributes_3_revision_number, standardattributes_3.created_at AS standardattributes_3_created_at, standardattributes_3.updated_at AS standardattributes_3_updated_at, tags_3.standard_attr_id AS tags_3_standard_attr_id, tags_3.tag AS tags_3_tag, networks_1.project_id AS networks_1_project_id, networks_1.id AS networks_1_id, networks_1.name AS networks_1_name, networks_1.status AS networks_1_status, networks_1.admin_state_up AS networks_1_admin_state_up, networks_1.vlan_ transparent AS networks_1_vlan_transparent, networks_1.availability_zone_hints AS networks_1_availability_zone_hints, networks_1.standard_attr_id AS n etworks_1_standard_attr_id, networksecuritybindings_1.network_id AS networksecuritybindings_1_network_id, networksecuritybindings_1.port_security_enab led AS networksecuritybindings_1_port_security_enabled, externalnetworks_1.network_id AS externalnetworks_1_network_id, externalnetworks_1.is_default AS externalnetworks_1_is_default, networkdnsdomains_1.network_id AS networkdnsdomains_1_network_id, networkdnsdomains_1.dns_domain AS networkdnsdomain s_1_dns_domain, qos_network_policy_bindings_1.policy_id AS qos_network_policy_bindings_1_policy_id, qos_network_policy_bindings_1.network_id AS qos_ne twork_policy_bindings_1_network_id FROM subnets LEFT OUTER JOIN subnet_service_types ON subnets.id = subnet_service_types.subnet_id LEFT OUTER JOIN subnetpools AS subnetpools_1 ON subnets.subnetpool_id = subnetpools_1.id LEFT OUTER JOIN subnetpoolprefixes AS subnetpoolprefixes_1 ON subnetpools_1.id = subnetpoolprefixes_1.subnetpool_id LEFT OUTER JOIN standardattributes AS standardattributes_1 ON standardattributes_1.id = subnetpools_1.standard_attr_id LEFT OUTER JOIN tags AS tags_1 ON standardattributes_1.id = tags_1.standard_attr_id LEFT OUTER JOIN ipallocationpools AS ipallocationpools_1 ON subnets.id = ipallocationpools_1.subnet_id LEFT OUTER JOIN dnsnameservers AS dnsnameservers_1 ON subnets.id = dnsnameservers_1.subnet_id LEFT OUTER JOIN subnetroutes AS subnetroutes_1 ON subnets.id = subnetroutes_1.subnet_id LEFT OUTER JOIN networkrbacs AS networkrbacs_1 ON subnets.network_id = networkrbacs_1.object_id LEFT OUTER JOIN standardattributes AS standardattributes_2 ON standardattributes_2.id = subnets.standard_attr_id LEFT OUTER JOIN tags AS tags_2 ON standardattributes_2.id = tags_2.standard_attr_id LEFT OUTER JOIN subnet_service_types AS subnet_service_types_1 ON subnets.id = subnet_service_types_1.subnet_id LEFT OUTER JOIN networks AS networks_1 ON networks_1.id = subnets.network_id LEFT OUTER JOIN networkrbacs AS networkrbacs_2 ON networks_1.id = networkrbacs_2.object_id LEFT OUTER JOIN (SELECT networkdhcpagentbindings_1.network_id AS networkdhcpagentbindings_1_network_id, networkdhcpagentbindings_1.dhcp_agent_id AS networkdhcpagentbindings_1_dhcp_agent_id, agents_1.id AS agents_1_id, agents_1.agent_type AS agents_1_agent_type, agents_1.binary AS agents_1_binary, agents_1.topic AS agents_1_topic, agents_1.host AS agents_1_host, agents_1.availability_zone AS agents_1_availability_zone, agents_1.admin_state_up AS agents_1_admin_state_up, agents_1.created_at AS agents_1_created_at, agents_1.started_at AS agents_1_started_at, agents_1.heartbeat_timestamp AS agents_1_heartbeat_timestamp, agents_1.description AS agents_1_description, agents_1.configurations AS agents_1_configurations, agents_1.resource_versions AS agents_1_resource_versions, agents_1.load AS agents_1_load FROM networkdhcpagentbindings AS networkdhcpagentbindings_1 JOIN agents AS agents_1 ON agents_1.id = networkdhcpagentbindings_1.dhcp_agent_id) AS anon_1 ON networks_1.id = anon_1.networkdhcpagentbindings_1_network_id LEFT OUTER JOIN standardattributes AS standardattributes_3 ON standardattributes_3.id = networks_1.standard_attr_id LEFT OUTER JOIN tags AS tags_3 ON standardattributes_3.id = tags_3.standard_attr_id LEFT OUTER JOIN networksecuritybindings AS networksecuritybindings_1 ON networks_1.id = networksecuritybindings_1.network_id LEFT OUTER JOIN externalnetworks AS externalnetworks_1 ON networks_1.id = externalnetworks_1.network_id LEFT OUTER JOIN networkdnsdomains AS networkdnsdomains_1 ON networks_1.id = networkdnsdomains_1.network_id LEFT OUTER JOIN qos_network_policy_bindings AS qos_network_policy_bindings_1 ON networks_1.id = qos_network_policy_bindings_1.network_id WHERE subnets.network_id = ? AND (subnet_service_types.service_type IS NULL OR subnet_service_types.service_type = ?) ORDER BY dnsnameservers_1."order" and will generate below output in sqlite 2.7.17 version(for UT test_create_port_no_device_owner_no_fallback) ('query = ', [(, None)]) but same query won't generate any records for sqlite 2.8.0 version(for same UT test_create_port_no_device_owner_no_fallback)