ecto_shorts icon indicating copy to clipboard operation
ecto_shorts copied to clipboard

Ensure schema module is loaded for function_exported.

Open eriknaslund opened this issue 7 months ago • 2 comments

Ensure schema module is loaded before checking to see if create_changeset/1 is exported.

Kernel.function_exported?/3 does NOT load a module in case it is not loaded.

This will, for example, cause tests to fail in some cases, because your module with create_changeset/1 definde will only be loaded if it has changed and needed to be recompiled.

If this happens then the EctoShorts erranously thinks that the function isn't defined, and tries to fall back to changeset/2 insted (which might not be defined).

The call to Code.ensure_loaded?(schema) will solve this problem if the schema module wasn't loaded, and it'll be a no-op if it's already loaded.

eriknaslund avatar Nov 30 '23 14:11 eriknaslund