Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ecto/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ defmodule Ecto.Schema do
# better to raise unknown type first than unsupported option.
type = check_field_type!(mod, name, type, opts)

if type == :any && !opts[:virtual] do
if type == :any && !opts[:virtual] && Module.get_attribute(mod, :ecto_source) do
raise ArgumentError,
"only virtual fields can have type :any, " <>
"invalid type for field #{inspect(name)}"
Expand Down Expand Up @@ -2301,6 +2301,7 @@ defmodule Ecto.Schema do
end

Module.put_attribute(module, :ecto_schema_defined, line)
Module.put_attribute(module, :ecto_source, source)

if Code.can_await_module_compilation?() do
Module.put_attribute(module, :after_verify, Ecto.Schema)
Expand Down
9 changes: 9 additions & 0 deletions test/ecto/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,15 @@ defmodule Ecto.SchemaTest do
end
end
end

# :any is allowed on embedded schema
defmodule EmbeddedFieldAny do
use Ecto.Schema

embedded_schema do
field :json, :any
end
end
end

defmodule FieldAnyVirtual do
Expand Down
Loading