Repository: marcosschroh/dataclasses-avroschema

Issue:
exclude_default is ignored on Pydantic model from the second call
**Describe the bug**
If you try to get avro schema from a pydantic model multiple times it starts ignoring the exclude_default feature

**To Reproduce**
```
import uuid
from dataclasses_avroschema.pydantic import AvroBaseModel
from pydantic import Field

class Test(AvroBaseModel):
    id: str = Field(  # type: ignore[call-arg]
        default_factory=lambda: str(uuid.uuid4()), metadata={"exclude_default": True}
    )

a = Test()
print(a.avro_schema())  # it's works as expected
print(a.avro_schema())  # it's not works as expected and the defaults are included inside the schema
```

as a workaround I've overridden the method avro_schema by putting the cache decorator

```
    @classmethod
    @cache
    def avro_schema(cls, case_type: Any = None, **kwargs: Any) -> str:
        return super().avro_schema(case_type=case_type, **kwargs)

```

**Expected behavior**
It should always exclude the default 


Discussion:
github-actions[bot]: [PR Preview Action](https://github.com/rossjrw/pr-preview-action) v1.4.8
:---:
:rocket: Deployed preview to https://marcosschroh.github.io/dataclasses-avroschema/pr-preview/pr-815/
on branch [`gh-pages`](https://github.com/marcosschroh/dataclasses-avroschema/tree/gh-pages) at 2024-12-06 17:47 UTC
<!-- Sticky Pull Request Commentpr-preview -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/815?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.48%. Comparing base [(`90e487b`)](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/commit/90e487b0dc497dacb6b622e10ae422e89c3a5483?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh) to head [(`e3fa811`)](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/commit/e3fa811ae4083e817c40eab1e801d2ec57579052?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #815   +/-   ##
=======================================
  Coverage   99.48%   99.48%           
=======================================
  Files          35       35           
  Lines        2130     2131    +1     
=======================================
+ Hits         2119     2120    +1     
  Misses         11       11           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/marcosschroh/dataclasses-avroschema/pull/815?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Marcos+Schroh).


Patch:
diff --git a/dataclasses_avroschema/fields/base.py b/dataclasses_avroschema/fields/base.py
index 11e60d1..69ecb0d 100644
--- a/dataclasses_avroschema/fields/base.py
+++ b/dataclasses_avroschema/fields/base.py
@@ -32,10 +32,17 @@ class Field:
     metadata: typing.Dict = dataclasses.field(default_factory=dict)
     model_metadata: utils.SchemaMetadata = dataclasses.field(default_factory=utils.SchemaMetadata)
     extra_default_types_allowed: typing.Tuple = dataclasses.field(default_factory=tuple)
+    # This is the metadata that the end user has defined in the dataclasses.Field or pydantic.Field
+    metadata_to_exclude: typing.List[str] = dataclasses.field(
+        default_factory=lambda: [
+            "exclude_default",
+            "inner_name",
+        ]
+    )
 
     def __post_init__(self) -> None:
-        self.exclude_default = self.metadata.pop("exclude_default", False)  # type: ignore
-        self.inner_name = self.metadata.pop("inner_name", None)  # type: ignore
+        self.exclude_default = self.metadata.get("exclude_default", False)  # type: ignore
+        self.inner_name = self.metadata.get("inner_name", None)  # type: ignore
 
     @property
     def avro_type(self) -> typing.Union[str, typing.Dict]:  # type: ignore
@@ -53,7 +60,7 @@ class Field:
         return inflection.singularize(name)
 
     def get_metadata(self) -> typing.List[typing.Tuple[str, str]]:
-        return [(name, value) for name, value in self.metadata.items()]
+        return [(name, value) for name, value in self.metadata.items() if name not in self.metadata_to_exclude]
 
     def render(self) -> OrderedDict:
         """


Test patch:
diff --git a/tests/schemas/pydantic/test_pydantic.py b/tests/schemas/pydantic/test_pydantic.py
index 8109ddd..365caa7 100644
--- a/tests/schemas/pydantic/test_pydantic.py
+++ b/tests/schemas/pydantic/test_pydantic.py
@@ -59,6 +59,9 @@ def test_exclude_default_from_schema(user_avro_json):
             schema_doc = False
 
     assert User.avro_schema() == json.dumps(user_avro_json)
+    # We execute again the test to make sure that that the result is the same
+    # related to https://github.com/marcosschroh/dataclasses-avroschema/issues/799
+    assert User.avro_schema() == json.dumps(user_avro_json)
 
 
 def test_pydantic_record_schema_with_metadata():