Getting warning: defining a Gettext backend by calling

I downloaded the new phoenix template installer.
I created a new instance of Phoenix.

I did:

mix ecto.create

I immediately get this new warning/error thing and I have no idea of its significance.
Why does the person that wrote the error expect me to know what this is?
What is the consequences of not dealing with it?
How do I deal with it? I have no idea what this means or what it is asking me to do, I never had this come up before.

warning: defining a Gettext backend by calling

    use Gettext, otp_app: ...

is deprecated. To define a backend, call:

    use Gettext.Backend, otp_app: :my_app

Then, instead of importing your backend, call this in your module:

    use Gettext, backend: MyApp.Gettext

  lib/app_web/gettext.ex:23: AppWeb.Gettext (module)

Generated app app
The database for App.Repo has been created

I literally am clueless.

What does this mean and what exactly is it asking me to do?

Itā€™s because gettext syntax has changed in the last versionā€¦ but itā€™s not too complicate to solve, just follow the replacement syntax in the warning

igniter has a mix task to automate this as well.

3 Likes

This is great!

Iā€™m also curious about why this is even surfacing? Iā€™m not really sure what is generating this deprecated code, but it seems like the ideal solution would be to just generate things in the updated format?

They will. The generators just havenā€™t been updated since the last release.

Hereā€™s the commit that changed the generators to use the new Gettext implementation:

2 Likes

Surely this is fixed in the latest generators given the 1.0 release.

1 Like

This is in :phoenix which hasnā€™t had a release since June. Not to be confused with phoenix_live_view reaching 1.0 the other day. It will be fixed in the next Phoenix update which Iā€™m guessing is coming fairly soon.

This is in generated code, not in Phoenix. So the latest mix phx.new should not include this issue, and no update to Phoenix will ever fix it (because itā€™s in generated code)

1 Like

It seems like this is waiting on a minor version bump, since there have been a few patch versions published since the fix. Maybe Iā€™ve missed why that is the case, though.

It may seem odd to be hung up on something which is both very clear (and very recently got more clear, which is great!) and just a warning. Itā€™s clearly confused a fair amount of people, however, which seems like a good reason by itself to just bump the minor version.

Thereā€™s also a bit of a confusing stance here. Elixir doesnā€™t let you ignore warnings, but in this case with (arguably) the biggest reason people come to Elixir, the recommendation is to ignore the warning. Itā€™s especially confusing for newcomers, since they didnā€™t write the code, so it doesnā€™t seem fair to expect them to not be able to disable the warning, and ask them to ignore it, but also tell them how to fix code they didnā€™t write, in a part of their app they probably donā€™t even really know about.

Maybe this just slipped through the cracks!

4 Likes

Below is an article via a Google Search that explains the error and what it is asking.

I donā€™t understand why the error itself is so cryptic to the point where the responsibility of explaining it needs to be offloaded onto tutorial writers found via a Google search. This feels like a constant pattern.

I understand perfectly fine as written here: šŸ„ Fixing the gettext warning in Phoenix | šŸ„ YellowDuck.be

Nope, the issue is still present with the latest version of phx_new:

16:55:36 ~/code/phoenix
user $ mix archive.install hex phx_new
Resolving Hex dependencies...
Resolution completed in 0.01s
New:
  phx_new 1.7.17
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 11 files (.ex)
Generated phx_new app
Generated archive "phx_new-1.7.17.ez" with MIX_ENV=prod
Found existing entry: /home/user/.asdf/installs/elixir/1.15.7-otp-25/.mix/archives/phx_new-1.7.14
Are you sure you want to replace it with "phx_new-1.7.17.ez"? [Yn] y
* creating /home/user/.asdf/installs/elixir/1.15.7-otp-25/.mix/archives/phx_new-1.7.17

16:56:11 ~/code/phoenix
user $ mix phx.new hello_phoenix

# Setup messages trimmed for brevity

16:56:35 ~/code/phoenix
user $ cd hello_phoenix/

16:56:38 ~/code/phoenix/hello_phoenix
user $ mix ecto.create

Compiling 15 files (.ex)
warning: defining a Gettext backend by calling

    use Gettext, otp_app: ...

is deprecated. To define a backend, call:

    use Gettext.Backend, otp_app: :my_app

Then, instead of importing your backend, call this in your module:

    use Gettext, backend: MyApp.Gettext

  lib/hello_phoenix_web/gettext.ex:23: HelloPhoenixWeb.Gettext (module)

Generated hello_phoenix app

2 Likes

This is indeed still an issue, as the generators rely on the code included in the latest Phoenix release.

The problem is that the current Phoenix main already contains some bigger changes to the generators for Phoenix 1.8 and 1.8 is not ready yet. As this really doesnā€™t shine a good light on Phoenix, Iā€™ll try to backport the gettext changes to 1.7 tomorrow and maybe get Chris to do a new release. Sorry for all the confusion this already has caused!

11 Likes

:scream: yikes

Seeing you on the job makes me confident it is resolved soon. Maybe also add a check to a pipeline to check for warnings on new project initialization so this wonā€™t happen again in the future.

1 Like

Iā€™m not sure this would help. gettext is locked to ~> 0.xx, which means any breaking change in gettext would still be fetched and cause issues even with no change to the phoenix project. The only solution to prevent such issues would be to lock any pre 1.0 dependency down more thoroughly.

1 Like

A nightly run of the pipeline (so without a Phoenix code change) would catch it, as creating a new project would cause a warning and the job would fail.

Better pinning (except an explicit version pin) is a partial solution, as it would still rely on dep maintainers to properly version their libs. Better double check with a nightly test suite.

If there is no such thing, let me know and Iā€™ll get my hands dirty.

2 Likes

Backport is done and will be released as part of 1.7.18. Itā€˜s now in the hand of Chris to do the release. We also updated the generators to use the new interpolation syntax. The goal is still to get 1.8 out soonā„¢ļø.

7 Likes

Phoenix 1.7.18 is out containing the updated generators! You can update the phx.new generators using

mix archive.install hex phx_new

Thanks to everyone for being patient and bringing this to our attention! And sorry that weā€™ve had this issue lingering for such a long time. Iā€™ll try to keep an eye on this to handle such situations faster in the future :slight_smile:

9 Likes