I am working on putting a GUI on top of @Nick612Haylund's Glassdoor scraper. When I run it, I get an error that I have found a bug:
Attached is the YXI with the code. Thoughts? Am I missing a step in the AyxPlugin or IncomingInterface classes?
Well, I definitely missed something. I wrote a bad loop in Python that was not filling in all of the fields in the Reviews output.
This is the original code:
def pushReviews(self, result: ScrapeResults): for review in result.reviews: self.ReviewsCreator.reset() self.ReviewFields[0].set_from_string(self.ReviewsCreator, result.GlassdoorId) i: int = 0 while i < len(result.reviews): self.ReviewFields[i+1].set_from_string(self.ReviewsCreator, review[i]) i = i + 1 self.parent.alteryx_engine.output_message(self.parent.n_tool_id, Sdk.EngineMessageType.info, str(i) + " review fields set. Rescord outputted") output = self.ReviewsCreator.finalize_record() self.parent.Reviews.push_record(output)
and this is the working code:
def pushReviews(self, result: ScrapeResults): for review in result.reviews: self.ReviewsCreator.reset() self.ReviewFields[0].set_from_string(self.ReviewsCreator, result.GlassdoorId) i: int = 0 while i < len(review): self.ReviewFields[i+1].set_from_string(self.ReviewsCreator, review[i]) i = i + 1 output = self.ReviewsCreator.finalize_record() self.parent.Reviews.push_record(output)
Pretty much the same, but if you look at the while loop in the middle, you will notice a change. This is the section that sets values in individual fields, but I was originally looping through the number of reviews rather than the number of fields in the review. I was limiting the import to 1 page (9 reviews) and have 16 fields in the output, so the last 7 fields were not getting values. Alteryx doesn't seem to like it when fields do not have a value and responded with the bug message.
EDIT:
I am attaching an updated YXI and a tester workflow for posterity.
I thought I posted a reply here...
Anyway, it turns out the bug was an error in one of my loops. This is the method that was causing the issue; the while loop in the middle was the culprit:
def pushReviews(self, result: ScrapeResults): for review in result.reviews: self.ReviewsCreator.reset() self.ReviewFields[0].set_from_string(self.ReviewsCreator, result.GlassdoorId) i: int = 0 while i < len(result.reviews): self.ReviewFields[i+1].set_from_string(self.ReviewsCreator, review[i]) i = i + 1 self.parent.alteryx_engine.output_message(self.parent.n_tool_id, Sdk.EngineMessageType.info, str(i) + " review fields set. Rescord outputted") output = self.ReviewsCreator.finalize_record() self.parent.Reviews.push_record(output)
And this is the corrected method:
def pushReviews(self, result: ScrapeResults): for review in result.reviews: self.ReviewsCreator.reset() self.ReviewFields[0].set_from_string(self.ReviewsCreator, result.GlassdoorId) i: int = 0 while i < len(review): self.ReviewFields[i+1].set_from_string(self.ReviewsCreator, review[i]) i = i + 1 output = self.ReviewsCreator.finalize_record() self.parent.Reviews.push_record(output)
What was happening was, rather than loop through the fields in each review, the while loop was looping through the the number of reviews. I was limiting the number of pages to 1, so the while loop was iterating 9 times, but there are 16 fields in the Reviews output. This means the last 7 fields were not getting a value. Alteryx seems to dislike this and was throwing the error as a result.
Attached is a YXI with corrected logic and a test workflow.
How did you debug the problem? I am knocking up a tool and it does very little at moment, but I am getting this error and can get no diagnostics about what is wrong.