Skip to content

Conversation

@shreddd
Copy link
Contributor

@shreddd shreddd commented Oct 4, 2025

No description provided.

@shreddd shreddd requested a review from eecavanna October 4, 2025 00:59
@eecavanna
Copy link

Please add PR description to help set context for reviewing.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive property filtering capabilities to the BERtron client, allowing users to filter entities based on their metadata properties using MongoDB-style queries. The enhancement enables filtering by property names, IDs, values, and supports various filter types including raw string matching, numeric values, regex patterns, and numeric ranges.

Key changes:

  • Added create_property_filter() method for building MongoDB $elemMatch queries
  • Extended geographic and source-based query methods to accept optional property filters
  • Added comprehensive example usage in the main execution block

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +158 to +173
elif property_type == "range":
# For range queries, we need to handle both single numeric_value
# and minimum_numeric_value/maximum_numeric_value pairs
# Use $or to match either case
elem_match_conditions["$or"] = [
{
"numeric_value": {
"$gte": property_value[0],
"$lte": property_value[1]
}
},
{
"minimum_numeric_value": {"$lte": property_value[1]},
"maximum_numeric_value": {"$gte": property_value[0]}
}
]
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No validation that property_value is a list/tuple with exactly 2 elements before accessing indices [0] and [1]. This will raise an IndexError if a single value or wrong format is passed.

Copilot uses AI. Check for mistakes.
Comment on lines +356 to +358
base_filter = {"ber_data_source": source}
if filter_dict:
base_filter.update(filter_dict)
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using update() can overwrite the ber_data_source key if filter_dict contains the same key. This could silently change the intended behavior. Consider using a merge strategy that preserves the base filter or validates for conflicts.

Copilot uses AI. Check for mistakes.
Comment on lines +371 to +373
base_filter = {"entity_type": entity_type}
if filter_dict:
base_filter.update(filter_dict)
Copy link

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as with find_entities_by_source: using update() can overwrite the entity_type key if filter_dict contains the same key, potentially changing the intended filtering behavior.

Suggested change
base_filter = {"entity_type": entity_type}
if filter_dict:
base_filter.update(filter_dict)
# Ensure the entity_type argument always takes precedence over filter_dict
base_filter = dict(filter_dict) if filter_dict else {}
base_filter["entity_type"] = entity_type

Copilot uses AI. Check for mistakes.
Copy link

@eecavanna eecavanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with this codebase. I skimmed the diff on my iPhone and nothing jumped out to me as problematic, other than the things Copilot reported (except one of them, which I clicked "Resolve conversation" on).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants