On 7/15/20 4:09 PM, Rodolfo Alonso Hernandez wrote:
Hi Thomas:
If I'm not wrong, the goal of this filtering is to remove all those subnets with service_type='network:routed'. Maybe you can check implementing an easier query: SELECT subnets.segment_id AS subnets_segment_id FROM subnets WHERE subnets.network_id = %(network_id_1)s AND NOT (EXISTS (SELECT * FROM subnet_service_types WHERE subnets.id <http://subnets.id> = subnet_service_types.subnet_id AND subnet_service_types.service_type = %(service_type_1)s))
That will be translated to python as:
query = test_db.context.session.query(subnet_obj.Subnet.db_model.segment_id) query = query.filter(subnet_obj.Subnet.db_model.network_id == network_id) if filtered_service_type: query = query.filter(~exists().where(and_( subnet_obj.Subnet.db_model.id <http://subnet_obj.Subnet.db_model.id> == service_type_model.subnet_id, service_type_model.service_type == filtered_service_type)))
Can you provide a UTs or a way to check the problem you are experiencing?
Regards.
Hi Rodolfo, Thanks for your help. I tried translating what you wrote above into a working code (ie: fixing a few variables here and there), which I sent as a new PR here: https://review.opendev.org/#/c/741429/ However, printing the result from SQLAlchemy shows that get_subnet_segment_ids() still returns None together with my other 2 subnets, so something must still be wrong. I'm not yet to the point I can write unit tests, just trying the code locally for the moment. Cheers, Thomas Goirand (zigo)