Skip to content

feat: An option to disable triggers validation #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

elfenlaid
Copy link

The changes introduce an option that disables triggers validation

The motivation behind the option is aimed mainly at test environments. Validation is great, but it works in an asynchronous manner, which gets in the way of sandboxed repos (Ecto.Adapters.SQL.Sandbox.mode(Repo, :manual))

So, when running tests, you can hit the following error:

(DBConnection.OwnershipError) cannot find ownership process for #PID
2025-06-14 16:16:31.087 [error] Task #PID<0.629.0> started from EctoWatch terminating
** (DBConnection.OwnershipError) cannot find ownership process for #PID<0.629.0>.

When using ownership, you must manage connections in one
of the four ways:

* By explicitly checking out a connection
* By explicitly allowing a spawned process
* By running the pool in shared mode
* By using :caller option with allowed process

The first two options require every new process to explicitly
check a connection out or be allowed by calling checkout or
allow respectively.

The third option requires a {:shared, pid} mode to be set.
If using shared mode in tests, make sure your tests are not
async.

The fourth option requires [caller: pid] to be used when
checking out a connection from the pool. The caller process
should already be allowed on a connection.

If you are reading this error, it means you have not done one
of the steps above or that the owner process has crashed.

See Ecto.Adapters.SQL.Sandbox docs for more information.
    (ecto_sql 3.12.1) lib/ecto/adapters/sql.ex:1093: Ecto.Adapters.SQL.raise_sql_call_error/1
    (ecto_watch 0.13.2) lib/ecto_watch/watcher_trigger_validator.ex:180: EctoWatch.WatcherTriggerValidator.sql_query/2
    (ecto_watch 0.13.2) lib/ecto_watch/watcher_trigger_validator.ex:147: EctoWatch.WatcherTriggerValidator.find_triggers/1
    (ecto_watch 0.13.2) lib/ecto_watch/watcher_trigger_validator.ex:114: anonymous fn/1 in EctoWatch.WatcherTriggerValidator.triggers_by_repo_mod/0
    (elixir 1.18.4) lib/map.ex:257: Map.do_map/2
    (elixir 1.18.4) lib/map.ex:251: Map.new_from_map/2
    (ecto_watch 0.13.2) lib/ecto_watch/watcher_trigger_validator.ex:38: EctoWatch.WatcherTriggerValidator.run/1
    (elixir 1.18.4) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
Function: &EctoWatch.WatcherTriggerValidator.run/1
    Args: [nil]

From my understanding, that happens because the validator tries to return a database connection to the pool, but isn't authorized to do that. Mostly because it was spawned outside test cases.

The validate_triggers? makes it possible to skip validation in tests and avoid the above error altogether.


That said, please let me know if you have any other ideas to avoid the mentioned scenario. I'm more than willing to cooperate on this.

Also, thank you for such a nice library! 🙇

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.

1 participant