Issue #6697: Fixed instances of _PyUnicode_AsString() result not checked for NULL
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 32fe835..16964d8 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -1257,7 +1257,8 @@
             assert(PyUnicode_Check(Zreplacement));
             ptoappend = _PyUnicode_AsStringAndSize(Zreplacement,
                                                   &ntoappend);
-            ntoappend = Py_SIZE(Zreplacement);
+            if (ptoappend == NULL)
+                goto Done;
         }
         else if (ch == 'f') {
             /* format microseconds */