mathesar-foundation / mathesar

Web application providing an intuitive user experience to databases.
https://mathesar.org/
GNU General Public License v3.0
2.28k stars 316 forks source link

Installation creates nonsensical cast functions #3555

Closed mathemancer closed 1 month ago

mathemancer commented 2 months ago

Description

The installation of cast functions currently creates many such functions which make no sense, and can only fail. For example, we create a function that attempts to cast a bigint to a mathesar_types.email. However, such a conversion is impossible. There's no such thing as a value which is both a valid integer and a valid email address.

Expected behavior

Only cast functions which make sense should be installed.

The main issue seems to be the constant db.types.categories.STRING_LIKE_TYPES. We use this to construct a bunch of textual cast functions in the db.types.operations.cast.create_textual_casts function. However, we consider many types (e.g., mathesar_types.email to be STRING_LIKE_TYPES, and most don't make sense as the target of arbitrary casts from other arbitrary types.

mathemancer commented 2 months ago

This was discovered while putting together DB-layer logic for determining the valid_target_types array for some types. Many (many) types consider mathesar_types.uri to be a valid_target_type (taking whether we have a custom cast function with that pair as the definition). We need to make sure only the correct target types are ... targeted ... by our custom casting functions for a given source type.