Repository: pydantic/pydantic

Issue:
`from_attributes=True` is ignored when validating a standard library datclass against a Pydantic dataclass
### Initial Checks

- [X] I confirm that I'm using Pydantic V2

### Description

When using a Pydantic dataclass with `TypeAdapter`, calling `validate_python(...)` on an arbitrary standard library dataclass instance raises a `pydantic_core._pydantic_core.ValidationError`, whether or not `from_attributes=True` is present.

The message is the same: `Input should be a dictionary or an instance of ...`.

Because:
- this works with Pydantic models inheriting from `BaseModel`;
- expecting only a dictionary or an instance of the validation dataclass more or less defeats the purpose of `from_attributes=True`;
- iirc this did not affect Pydantic v1 ORM mode;

I assume this is a bug.

### Example Code

```Python
import dataclasses

import pydantic
from pydantic import TypeAdapter, BaseModel


class ValidationModel(BaseModel):
    message: str


@pydantic.dataclasses.dataclass
class ValidationDataclass:
    message: str


@dataclasses.dataclass
class Data:
    message: str


model_validator = TypeAdapter(ValidationModel)
print(model_validator.validate_python(
    Data(message="hello BaseModel!"), from_attributes=True)
)

dataclass_validator = TypeAdapter(ValidationDataclass)
print(dataclass_validator.validate_python(
    Data(message="hello dataclass!"), from_attributes=True)
)
```


### Python, Pydantic & OS Version

```Text
             pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=true
                 install path: /home/loris/.cache/pypoetry/virtualenvs/fastapi-pydantic-v2-QLAxixyf-py3.11/lib/python3.11/site-packages/pydantic
               python version: 3.11.4 (main, Jun  9 2023, 07:59:55) [GCC 12.3.0]
                     platform: Linux-6.2.0-33-generic-x86_64-with-glibc2.37
             related packages: fastapi-0.103.2 typing_extensions-4.8.0
```



Discussion:
Hi @Hellzed,

Thanks for reporting this 😄. We actually don't currently support `from_attributes` specification when using `TypeAdapter` with a `pydantic` dataclass. This is part of the reason why (pydantic) dataclass validation is actually faster than BaseModel validation. Thus, this actually isn't a bug, but more of a feature request, and one that isn't currently on our roadmap.

That being said, I do think that this is certainly under-documented, so I'll plan to add a docs update to reflect this more clearly in order to address this issue 👍.

Resolving patch:
diff --git a/pydantic/config.py b/pydantic/config.py
--- a/pydantic/config.py
+++ b/pydantic/config.py
@@ -164,6 +164,40 @@ class User(BaseModel):
     """
     Whether to populate models with the `value` property of enums, rather than the raw enum.
     This may be useful if you want to serialize `model.model_dump()` later. Defaults to `False`.
+
+    !!! note
+        If you have an `Optional[Enum]` value that you set a default for, you need to use `validate_default=True`
+        for said Field to ensure that the `use_enum_values` flag takes effect on the default, as extracting an
+        enum's value occurs during validation, not serialization.
+
+    ```py
+    from enum import Enum
+    from typing import Optional
+
+    from pydantic import BaseModel, ConfigDict, Field
+
+
+    class SomeEnum(Enum):
+        FOO = 'foo'
+        BAR = 'bar'
+        BAZ = 'baz'
+
+
+    class SomeModel(BaseModel):
+        model_config = ConfigDict(use_enum_values=True)
+
+        some_enum: SomeEnum
+        another_enum: Optional[SomeEnum] = Field(default=SomeEnum.FOO, validate_default=True)
+
+
+    model1 = SomeModel(some_enum=SomeEnum.BAR)
+    print(model1.model_dump())
+    # {'some_enum': 'bar', 'another_enum': 'foo'}
+
+    model2 = SomeModel(some_enum=SomeEnum.BAR, another_enum=SomeEnum.BAZ)
+    print(model2.model_dump())
+    #> {'some_enum': 'bar', 'another_enum': 'baz'}
+    ```
     """
 
     validate_assignment: bool
diff --git a/pydantic/type_adapter.py b/pydantic/type_adapter.py
--- a/pydantic/type_adapter.py
+++ b/pydantic/type_adapter.py
@@ -273,6 +273,10 @@ def validate_python(
             from_attributes: Whether to extract data from object attributes.
             context: Additional context to pass to the validator.
 
+        !!! note
+            When using `TypeAdapter` with a Pydantic `dataclass`, the use of the `from_attributes`
+            argument is not supported.
+
         Returns:
             The validated object.
         """


Test patch: