In case you missed the announcement: Alteryx One is here, and so is the Spring Release! Learn more about these new and exciting releases here!

Dev Space

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.

Python SDK: "You have found a bug. Replicate, then let us know."`

tlarsen7572
11 - Bolide
11 - Bolide

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:

SNAG-0005.png

 

Attached is the YXI with the code.  Thoughts?  Am I missing a step in the AyxPlugin or IncomingInterface classes?

 

3 REPLIES 3
tlarsen7572
11 - Bolide
11 - Bolide

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.

tlarsen7572
11 - Bolide
11 - Bolide

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.

Hiblet
10 - Fireball

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.