ArgumentError :ets.lookup in Absinthe Middleware using FunWithFlags

I’m trying to use FunWithFlags.enabled? (ref fwf) inside an absinthe middleware but I got the following error:

(ArgumentError) argument error
    (stdlib) :ets.lookup(:fun_with_flags_cache, :some_flag)

  │ lib/fun_with_flags/store/cache.ex:35: FunWithFlags.Store.Cache.get/1
  │ lib/fun_with_flags/store.ex:12: FunWithFlags.Store.lookup/1
  │ lib/fun_with_flags.ex:77: FunWithFlags.enabled?/2

I haven’t tried too much. I just narrowed down where the issue is happening. I’m guessing that the middleware compiles before the :some_flag record (or maybe the :fun_with_flags_cache table) is created and then failed because there is no record/table.

This link says:

It stores flag information in Redis or a relational DB (PostgreSQL or MySQL, with Ecto) for persistence and synchronization across different nodes, but it also maintains a local cache in an ETS table for fast lookups. When flags are added or toggled on a node, the other nodes are notified via PubSub and reload their local ETS caches

So I’m guessing one option could be disable the ETS with the following config:

config :fun_with_flags, :cache,
  enabled: false,
  ttl: 900

But we lost all of the benefits of the cache.

Anyway, Any thought are welcome. Thanks in advance.
Thanks! :smiley:

Note: It doesn’t work adding the config. :frowning:

Can you show how you are using it?

Hi @benwilson512, it is something like:

defmodule MyApp.Schema do
use Absinthe.Schema
  def middleware(middleware, field, object) do
  FunWithFlags.enabled?(:some_flag) # <-- (ArgumentError) argument error (stdlib) :ets.lookup...

I posted almost the same question in stackoverflow to cover more land.


Yeah the issue here is that this function is actually run at compile time. This means that your ets tables are likely not loaded. Using the persistent_term schema backend would probably help (in that it will refresh the value at runtime), but I think this still runs at compile time to do a check.


Hey @benwilson512 Thanks for reply. We ended using an env variable in the middle function and inside the middleware module we were able to use FeatureFlags. BTW, I’m enjoying reading you book, thank you for writing it. Such a gem for GraphQL API crafters.