]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻️ Update FastAPI People logic with new Pydantic (#9985)
authorSebastián Ramírez <tiangolo@gmail.com>
Wed, 2 Aug 2023 15:57:20 +0000 (17:57 +0200)
committerGitHub <noreply@github.com>
Wed, 2 Aug 2023 15:57:20 +0000 (17:57 +0200)
.github/actions/people/Dockerfile
.github/actions/people/app/main.py

index fa4197e6a88d1634814fda58cd5533bf51612f82..6d65f1c2bfce013dd5ca9211d3f1a25356d66d02 100644 (file)
@@ -1,6 +1,6 @@
 FROM python:3.7
 
-RUN pip install httpx PyGithub "pydantic==1.5.1" "pyyaml>=5.3.1,<6.0.0"
+RUN pip install httpx PyGithub "pydantic==2.0.2" "pyyaml>=5.3.1,<6.0.0"
 
 COPY ./app /app
 
index b11e3456db58aa0e4ce57a4b6227d7e4a558ebf3..cb6b229e8e67e0c4ebc34b3004b2692c05d165b0 100644 (file)
@@ -9,7 +9,8 @@ from typing import Any, Container, DefaultDict, Dict, List, Set, Union
 import httpx
 import yaml
 from github import Github
-from pydantic import BaseModel, BaseSettings, SecretStr
+from pydantic import BaseModel, SecretStr
+from pydantic_settings import BaseSettings
 
 github_graphql_url = "https://api.github.com/graphql"
 questions_category_id = "MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyMDAxNDM0"
@@ -382,6 +383,7 @@ def get_graphql_response(
     data = response.json()
     if "errors" in data:
         logging.error(f"Errors in response, after: {after}, category_id: {category_id}")
+        logging.error(data["errors"])
         logging.error(response.text)
         raise RuntimeError(response.text)
     return data
@@ -389,7 +391,7 @@ def get_graphql_response(
 
 def get_graphql_issue_edges(*, settings: Settings, after: Union[str, None] = None):
     data = get_graphql_response(settings=settings, query=issues_query, after=after)
-    graphql_response = IssuesResponse.parse_obj(data)
+    graphql_response = IssuesResponse.model_validate(data)
     return graphql_response.data.repository.issues.edges
 
 
@@ -404,19 +406,19 @@ def get_graphql_question_discussion_edges(
         after=after,
         category_id=questions_category_id,
     )
-    graphql_response = DiscussionsResponse.parse_obj(data)
+    graphql_response = DiscussionsResponse.model_validate(data)
     return graphql_response.data.repository.discussions.edges
 
 
 def get_graphql_pr_edges(*, settings: Settings, after: Union[str, None] = None):
     data = get_graphql_response(settings=settings, query=prs_query, after=after)
-    graphql_response = PRsResponse.parse_obj(data)
+    graphql_response = PRsResponse.model_validate(data)
     return graphql_response.data.repository.pullRequests.edges
 
 
 def get_graphql_sponsor_edges(*, settings: Settings, after: Union[str, None] = None):
     data = get_graphql_response(settings=settings, query=sponsors_query, after=after)
-    graphql_response = SponsorsResponse.parse_obj(data)
+    graphql_response = SponsorsResponse.model_validate(data)
     return graphql_response.data.user.sponsorshipsAsMaintainer.edges
 
 
@@ -607,7 +609,7 @@ def get_top_users(
 if __name__ == "__main__":
     logging.basicConfig(level=logging.INFO)
     settings = Settings()
-    logging.info(f"Using config: {settings.json()}")
+    logging.info(f"Using config: {settings.model_dump_json()}")
     g = Github(settings.input_token.get_secret_value())
     repo = g.get_repo(settings.github_repository)
     question_commentors, question_last_month_commentors, question_authors = get_experts(