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
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?
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)
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.
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.
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
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!
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.
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.
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.
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ā¢ļø.
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