Skip to content

Commit

Permalink
bug, add frontend check
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpkane committed Jan 30, 2025
1 parent 9ddc487 commit 8b28480
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fos from "@fiftyone/state";
import { isMatchingAtom, stringExcludeAtom } from "@fiftyone/state";
import { getFetchFunction } from "@fiftyone/utilities";
import { getFetchFunction, isObjectIdString } from "@fiftyone/utilities";
import { atomFamily, selectorFamily } from "recoil";
import { labelTagsCount } from "../../Sidebar/Entries/EntryCounts";
import { nullSort } from "../utils";
Expand Down Expand Up @@ -57,6 +57,11 @@ export const stringSearchResults = selectorFamily<
({ path, modal, filter }) =>
async ({ get }) => {
const search = filter ? "" : get(stringSearch({ modal, path }));
// for object id searches, skip request when the string is not <= 24 hex
if (get(fos.isObjectIdField(path)) && !isObjectIdString(search, false)) {
return { values: [] };
}

const sorting = get(fos.sortFilterResults(modal));
const mixed = get(fos.groupStatistics(modal)) === "group";
const selected = get(fos.stringSelectedValuesAtom({ path, modal }));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { SelectorValidationError } from "@fiftyone/components";
import { isObjectIdField, snackbarErrors } from "@fiftyone/state";
import { isObjectIdString } from "@fiftyone/utilities";
import { RecoilState, useRecoilCallback } from "recoil";
import { Result } from "./Result";
import type { RecoilState } from "recoil";
import { useRecoilCallback } from "recoil";
import type { Result } from "./Result";

export default function (
modal: boolean,
Expand Down
4 changes: 2 additions & 2 deletions app/packages/utilities/src/type-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export function isHex(value: string) {
return /[0-9a-f]{24}/g.test(value);
}

export function isObjectIdString(value: string) {
return isHex(value) && value.length === 24;
export function isObjectIdString(value: string, strict = true) {
return isHex(value) && strict ? value.length === 24 : value.length <= 24;
}

export type NumberKeyObjectType<V = unknown> = {
Expand Down
2 changes: 1 addition & 1 deletion fiftyone/server/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ async def _do_distinct_pipeline(

def _add_search(query: DistinctQuery):
# strip chars after 24
search = query.search[:_TWENTY_FOUR]
if query.is_object_id_field:
search = query.search[:_TWENTY_FOUR]
add = (_TWENTY_FOUR - len(search)) * "0"
if add:
search = f"{search}{add}"
Expand Down

0 comments on commit 8b28480

Please sign in to comment.