feat: allow float inputs to accept integers

Pydantic automatically casts ints to floats.
This commit is contained in:
psychedelicious 2023-09-04 11:22:31 +10:00
parent a765f01c08
commit 92975130bd
3 changed files with 12 additions and 2 deletions

View File

@ -112,6 +112,10 @@ def are_connection_types_compatible(from_type: Any, to_type: Any) -> bool:
if to_type in get_args(from_type): if to_type in get_args(from_type):
return True return True
# allow int -> float, pydantic will cast for us
if from_type is int and to_type is float:
return True
# if not issubclass(from_type, to_type): # if not issubclass(from_type, to_type):
if not is_union_subtype(from_type, to_type): if not is_union_subtype(from_type, to_type):
return False return False

View File

@ -120,12 +120,15 @@ export const useIsValidConnection = () => {
const isCollectionToGenericCollection = const isCollectionToGenericCollection =
targetType === 'Collection' && COLLECTION_TYPES.includes(sourceType); targetType === 'Collection' && COLLECTION_TYPES.includes(sourceType);
const isIntToFloat = sourceType === 'integer' && targetType === 'float';
return ( return (
isCollectionItemToNonCollection || isCollectionItemToNonCollection ||
isNonCollectionToCollectionItem || isNonCollectionToCollectionItem ||
isAnythingToPolymorphicOfSameBaseType || isAnythingToPolymorphicOfSameBaseType ||
isGenericCollectionToAnyCollectionOrPolymorphic || isGenericCollectionToAnyCollectionOrPolymorphic ||
isCollectionToGenericCollection isCollectionToGenericCollection ||
isIntToFloat
); );
} }

View File

@ -113,13 +113,16 @@ export const makeConnectionErrorSelector = (
const isCollectionToGenericCollection = const isCollectionToGenericCollection =
targetType === 'Collection' && COLLECTION_TYPES.includes(sourceType); targetType === 'Collection' && COLLECTION_TYPES.includes(sourceType);
const isIntToFloat = sourceType === 'integer' && targetType === 'float';
if ( if (
!( !(
isCollectionItemToNonCollection || isCollectionItemToNonCollection ||
isNonCollectionToCollectionItem || isNonCollectionToCollectionItem ||
isAnythingToPolymorphicOfSameBaseType || isAnythingToPolymorphicOfSameBaseType ||
isGenericCollectionToAnyCollectionOrPolymorphic || isGenericCollectionToAnyCollectionOrPolymorphic ||
isCollectionToGenericCollection isCollectionToGenericCollection ||
isIntToFloat
) )
) { ) {
return 'Field types must match'; return 'Field types must match';