szaszm commented on code in PR #1863:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1863#discussion_r1775039492


##########
extensions/python/types/PyProcessSession.h:
##########
@@ -39,6 +39,7 @@ class PyProcessSession {
   void remove(const std::shared_ptr<core::FlowFile>& flow_file);
   std::string getContentsAsString(const std::shared_ptr<core::FlowFile>& 
flow_file);
   void putAttribute(const std::shared_ptr<core::FlowFile>& flow_file, 
std::string_view key, const std::string& value);
+  gsl::not_null<core::ProcessSession*> getSession() const { return session_; }

Review Comment:
   This should return a reference instead.



##########
extensions/python/types/PyRecordSetReader.cpp:
##########
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+a * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "PyRecordSetReader.h"
+#include "rapidjson/writer.h"
+#include "rapidjson/stream.h"
+
+#include "PyProcessSession.h"
+#include "PyScriptFlowFile.h"
+
+extern "C" {
+namespace org::apache::nifi::minifi::extensions::python {
+
+static PyMethodDef PyRecordSetReader_methods[] = {  // 
NOLINT(cppcoreguidelines-avoid-c-arrays)
+    {"read", (PyCFunction) PyRecordSetReader::read, METH_VARARGS, nullptr},
+    {}  /* Sentinel */
+};
+
+static PyType_Slot PyRecordSetReaderTypeSpecSlots[] = {  // 
NOLINT(cppcoreguidelines-avoid-c-arrays)
+    {Py_tp_dealloc, 
reinterpret_cast<void*>(pythonAllocatedInstanceDealloc<PyRecordSetReader>)},
+    {Py_tp_init, reinterpret_cast<void*>(PyRecordSetReader::init)},
+    {Py_tp_methods, reinterpret_cast<void*>(PyRecordSetReader_methods)},
+    {Py_tp_new, 
reinterpret_cast<void*>(newPythonAllocatedInstance<PyRecordSetReader>)},
+    {}  /* Sentinel */
+};
+
+static PyType_Spec PyRecordSetReaderTypeSpec{
+    .name = "minifi_native.RecordSetReader",
+    .basicsize = sizeof(PyRecordSetReader),
+    .itemsize = 0,
+    .flags = Py_TPFLAGS_DEFAULT,
+    .slots = PyRecordSetReaderTypeSpecSlots
+};
+
+int PyRecordSetReader::init(PyRecordSetReader* self, PyObject* args, 
PyObject*) {

Review Comment:
   If the parameters are not nullable, they should be changed to references, or 
if the python API doesn't allow that, we could add a `gsl_Expects` check. If 
they CAN be null, and it's a user error, then we should create a python error 
or exception.
   I'm pretty sure at least self is not nullable, because it's dereferenced 
without a check on line 58.



##########
extensions/python/types/PyProcessSession.cpp:
##########
@@ -178,14 +178,24 @@ PyObject* 
PyProcessSessionObject::get(PyProcessSessionObject* self, PyObject*) {
   return object::returnReference(nullptr);
 }
 
-PyObject* PyProcessSessionObject::create(PyProcessSessionObject* self, 
PyObject*) {
+PyObject* PyProcessSessionObject::create(PyProcessSessionObject* self, 
PyObject* args) {
   auto session = self->process_session_.lock();
   if (!session) {
     PyErr_SetString(PyExc_AttributeError, "tried reading process session 
outside 'on_trigger'");
     return nullptr;
   }
 
-  if (auto flow_file = session->create(nullptr))
+  std::shared_ptr<core::FlowFile> parent_flow_file;
+  auto arg_size = PyTuple_Size(args);
+  if (arg_size > 0) {
+    PyObject* script_flow_file = nullptr;
+    if (!PyArg_ParseTuple(args, "O!", PyScriptFlowFile::typeObject(), 
&script_flow_file)) {
+      return nullptr;
+    }

Review Comment:
   I'm not sure returning null when the parent flow file is missing is the best 
approach. What about throwing an error when it's present, but invalid?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to