line-bot-sdk-python icon indicating copy to clipboard operation
line-bot-sdk-python copied to clipboard

Update pydantic to v2

Open tokuhirom opened this issue 2 years ago • 3 comments

pydantic v2 is not backward compatible. We need to upgrade it.

tokuhirom avatar Jul 25 '23 05:07 tokuhirom

We need to rewrite PythonNextgenCustomClientGenerator with the latest style.

diff --git generator/src/main/java/line/bot/generator/PythonNextgenCustomClientGenerator.java generator/src/main/java/line/bot/generator/PythonNextgenCustomClientGenerator.java
index 7d84030..e0e57f1 100644
--- generator/src/main/java/line/bot/generator/PythonNextgenCustomClientGenerator.java
+++ generator/src/main/java/line/bot/generator/PythonNextgenCustomClientGenerator.java
@@ -443,10 +443,10 @@ public class PythonNextgenCustomClientGenerator extends AbstractPythonCodegen im
         if (cp.isArray) {
             String constraints = "";
             if (cp.maxItems != null) {
-                constraints += String.format(Locale.ROOT, ", max_items=%d", cp.maxItems);
+                constraints += String.format(Locale.ROOT, ", max_length=%d", cp.maxItems);
             }
             if (cp.minItems != null) {
-                constraints += String.format(Locale.ROOT, ", min_items=%d", cp.minItems);
+                constraints += String.format(Locale.ROOT, ", min_length=%d", cp.minItems);
             }
             if (cp.getUniqueItems()) {
                 constraints += ", unique_items=True";
@@ -723,10 +723,10 @@ public class PythonNextgenCustomClientGenerator extends AbstractPythonCodegen im
         if (cp.isArray) {
             String constraints = "";
             if (cp.maxItems != null) {
-                constraints += String.format(Locale.ROOT, ", max_items=%d", cp.maxItems);
+                constraints += String.format(Locale.ROOT, ", max_length=%d", cp.maxItems);
             }
             if (cp.minItems != null) {
-                constraints += String.format(Locale.ROOT, ", min_items=%d", cp.minItems);
+                constraints += String.format(Locale.ROOT, ", min_length=%d", cp.minItems);
             }
             if (cp.getUniqueItems()) {
                 constraints += ", unique_items=True";

tokuhirom avatar Jul 25 '23 05:07 tokuhirom

BTW, there's a remaining error.

================================== short test summary info ===================================
FAILED tests/v3/test_webhook.py::TestWebhookParser::test_parse - TypeError: unhashable type: 'ModelPrivateAttr'
FAILED tests/v3/test_webhook.py::TestWebhookParser::test_parse_webhook_req_without_destination - TypeError: unhashable type: 'ModelPrivateAttr'
FAILED tests/v3/test_webhook.py::TestWebhookHandler::test_handler - TypeError: unhashable type: 'ModelPrivateAttr'

Why it's happened?

tokuhirom avatar Jul 25 '23 05:07 tokuhirom

https://docs.pydantic.dev/latest/migration/ There's a migration guide.

tokuhirom avatar Jul 25 '23 05:07 tokuhirom