peewee update thrown exception 'UnknownField' object has no attribute 'get_sort_key' - peewee

code:
query = Order.update(is_review=1, review_time=review_time).where(Order.order_sn == order_sn)
query.execute()
exception:
cursor = database.execute(self)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\peewee.py", line 2952, in execute
sql, params = ctx.sql(query).query()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\peewee.py", line 601, in sql
return obj.__sql__(self)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\peewee.py", line 2363, in __sql__
for k, v in sorted(self._update.items(), key=ctx.column_sort_key):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\peewee.py", line 555, in column_sort_key
return item[0].get_sort_key(self)
AttributeError: 'UnknownField' object has no attribute 'get_sort_key'
environment:
peewee version:3.9.5
python:3.7

I notice that you have posted this as a GitHub issue on the Peewee issue tracker as well. I've responded to your ticket and will paste my response here for anyone else:
You are clearly using models generated using the pwiz tool. If pwiz cannot determine the right field type to use for a column, it uses a placeholder "UnknownField". You will need to edit your model definitions and replace the UnknownField with an appropriate field type (e.g. TextField, IntegerField, whatever) if you wish to be able to use it in queries.

Related

Transfer Property ids (Array) to other TestCases in SoapUI/Groovy

I have an API to get list of ids, name, data etc. (TestCase name GET-APIs_OrderdByID_ASC)
I want to transfer those IDs to other following TestCases in same TestSuite or other TestSuite.
In SOAPUI, Property Transfer works within TestSteps in same TestCase. (Using OpenSource version). I need to transfer the property value among different TestCases / TestSuites.
Below is the code that I can extract ids from one testCase and also name of testCases/testSteps where I want to transfer.
import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.support.types.StringToStringMap
import groovy.json.*
def project = context.testCase.testSuite.project
def TestSuite = project.getTestSuiteByName("APIs")
def TestCase = TestSuite.getTestCaseList()
def TestStep = TestCase.testStepList
def request = testRunner.testCase.getTestStepByName("List_of_APIs_OrderByID_ASC")
def response = request.getPropertyValue("Response")
def JsonSlurperResponse = new JsonSlurper().parseText(response)
def Steps = TestStep.drop(3)
log.info JsonSlurperResponse.data.id
def id = JsonSlurperResponse.data.id
Steps.each {
it.getAt(0).setPropertyValue("apiId", id.toString())
log.info it.getAt(0).name
}
If I run above code, all the array values of id [1, 2, 10, 11, 12, 13, 14, 15, 16, 17, 18] are set to each of the following testSteps
I looked some other SO questions
Property transfer in SOAPUI using groovy script
groovy-script-and-property-transfer-in-soapui
Can anyone help me out. :-)
I have done something with datasinks as Leminou suggests.
Datasinks are a good solution for this. In test A, create a datasink step to persist the values of interest. Then in the target step, use a data source step, which links to the file generated by the datasink earlier.
The data sink can be configured to append after each test or start afresh.
If you're struggling to tease out the values for the datasink, create a groovy step that returns the single value you want, then in the datasink step, invoke the groovy.
Sounds a little convoluted, but it works.
You can use project level properties or testSuiteLevel properties or testCase Properties.
This way you can achieve the same thing that you get from Property Transfer step but in a different way.
Write a groovy step in the source test case to setProperty(save values you want to use later)
testRunner.testCase.setPropertyValue("TCaseProp", "TestCase")
testRunner.testCase.testSuite.setPropertyValue("TSuiteProp","TestSuite")
testRunner.testCase.testSuite.project.setPropertyValue("ProjectLevel","ProjectLevelProperty")
"TCaseProp" is the name of the property. you can give any name
"TestCase" is the value you want to store. You can extract this value and use a variable
for example
def val="9000"
testRunner.testCase.setPropertyValue("TCaseProp", val)
You can use that property in other case of same suite. If you want to use across different suites you can define project level property
use the below syntax in target testcase request
${#Project#ProjectLevel}
${#TestCase#TCaseProp}
${#TestSuite#TCaseProp}
<convertCurrency>${#TestSuite#TCaseProp}</ssp:SystemUsername>
System will automatically replace the property value in above request
https://www.soapui.org/scripting-properties/tips-tricks.html <-- Helpful link which can explain in detail about property transfer
Well the following Script works.
Just to change as
Steps.each { s ->
id.each { i ->
s.getAt(0).setPropertyValue("apiId", i.toString())
}
}
Here id is a ArrayList type. So We can loop through the List.
PS: We can do the same using for loop.

Issue saving a JSON string to a SQL Server database

My Angular web application currently serializes/deserializes JSON objects to/from local storage using the HTML5 localStorage object. We are now attempting to save and retrieve those same JSON objects to/from a SQL Server table.
I am however having difficultly as I try to save a JSON string using the following SQL UPDATE:
UPDATE [rz37883_SQLServer].[dbo].[RAGEDashboard]
SET
image = '{"widgets":[{"title":"Bar Chart","name":"chart_bar","style":{},"size":{"width":"50%","height":320},"dataModelOptions":{"title":{"text":"Bar Chart","position":"bottom"},"legend":{"visible":true,"position":"top"},"seriesDefaults":{"type":"bar","stack":false},"series":[{"field":"field1","name":"MTM"}],"dataSource":{"data":[{"field1":236151654.592439},{"field1":103612357.347808},{"field1":267066579.129913},{"field1":582355005.154486},{"field1":-9422699.958631}],"table":null},"valueAxis":{"labels":{"format":"{0:c}","rotation":-30},"line":{"visible":false},"axisCrossingValue":0},"categoryAxis":{"categories":["London","New York","Dubai","Paris","Stockholm"],"majorGridLines":{"visible":false},"labels":{"rotation":0,"margin":20}},"tooltip":{"visible":true,"template":"#= series.name #: #= kendo.format('{0:C0}', value) #"},"dimensions":[{"dimension":"BookingLocation","hierarchy":false,"id":0}],"riskMeasures":[{"name":"MTM","kri_group":"[MTM:MTM]","cube_vector":"MTM:MTM","aggreg_formula":"SUM(MTM:MTM)","id":0}]},"initImage":"images2/bar_chart.png","gadgetConfigured":true}]}'
WHERE [RAGEDashboardConfig_userid] = 'bobmazzo1234'
AND id = 1441288790
The SQL Server error message is:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '{'.
In the angular directive code, the item object currently gets saved to localStorage as follows.
save: function (widgets) {
//'widgets' are mapped to the 'serialized' var using _.map()
item = JSON.stringify(item);
this.storage.setItem(this.id, item);
}
I'm now wiring up an http request, which will call down into a c# API layer using MS WebAPI.
The problem here is that I'm simply trying to manually update the SQL Server table so I can test the retrieve functionality.
I think it's because you have a couple of single quotes in the string. You have to escape them, and ironically, a single quote is the escape character.
Here's the slight modification I made:
Original: kendo.format('{0:C0}', value)
Modified: kendo.format(''{0:C0}'', value)
Try changing your string to this and see if it fixes the issue:
UPDATE [rz37883_SQLServer].[dbo].[RAGEDashboard]
SET
image =
'{"widgets":[{"title":"Bar Chart","name":"chart_bar","style":{},"size":{"width":"50%","height":320},"dataModelOptions":{"title":{"text":"Bar Chart","position":"bottom"},"legend":{"visible":true,"position":"top"},"seriesDefaults":{"type":"bar","stack":false},"series":[{"field":"field1","name":"MTM"}],"dataSource":{"data":[{"field1":236151654.592439},{"field1":103612357.347808},{"field1":267066579.129913},{"field1":582355005.154486},{"field1":-9422699.958631}],"table":null},"valueAxis":{"labels":{"format":"{0:c}","rotation":-30},"line":{"visible":false},"axisCrossingValue":0},"categoryAxis":{"categories":["London","New York","Dubai","Paris","Stockholm"],"majorGridLines":{"visible":false},"labels":{"rotation":0,"margin":20}},"tooltip":{"visible":true,"template":"#= series.name #: #= kendo.format(''{0:C0}'', value) #"},"dimensions":[{"dimension":"BookingLocation","hierarchy":false,"id":0}],"riskMeasures":[{"name":"MTM","kri_group":"[MTM:MTM]","cube_vector":"MTM:MTM","aggreg_formula":"SUM(MTM:MTM)","id":0}]},"initImage":"images2/bar_chart.png","gadgetConfigured":true}]}'
WHERE [RAGEDashboardConfig_userid]='bobmazzo1234' and id = 1441288790

call some code in file and than in static block Magento

Hi i have a code which select the particular select attribute value of a product
<?php $attribute_value = $_product->getAttributeText('highligted_features');
print_r($attribute_value);
?>
when i am using this in view file it works properly
but when i place this code in a different file and call that file in
static block
and
than when i call that block in file it gives 500 internal server error
.
when i
Check attribute is not available in used in Product list attribute setting .Thus you cannot getting in other pages,If you using catalog product flat then flat table is not include highligted_features attribute in it columns

TransientError with Google App Engine Search

I'm trying to run a query and sorting by a date field.
q = self.request.get("q")
index = search.Index(name="transaction")
sort_options = search.SortOptions(
expressions=[
search.SortExpression(expression='timestamp_date', direction=search.SortExpression.DESCENDING)
],
limit=1000)
options = search.QueryOptions(limit=30, cursor=search.Cursor(), sort_options=sort_options)
results = index.search(search.Query(query_string=q, options=options))
On the development server, the code works but the results are not correctly sorted. On the production server it doesn't work at all; It gives the following error:
Search failed
Traceback (most recent call last):
File "/base/data/home/apps/s~xxx/pre-24.359846149527858049/main.py", line 78, in get
results = index.search(search.Query(query_string=q, options=options))
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 2609, in search
_CheckStatus(response.status())
File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/search/search.py", line 414, in _CheckStatus
raise _ERROR_MAP[status.code()](status.error_detail())
TransientError
I'm wondering how to make it work on the production server and how to sort correctly on the development server. I know its experimental technology, but I wanted to check to see if this was something I was overlooking
You need to provide a default value for all SortExpressions. This will be made clear in a forthcoming release. Also there is no explicit support for default Date values yet, so you need to put a default numeric value representing the number of days since 1970-01-01. In the code below, I am using the date 1970-01-01 as the default by specifying a value of 0.
sort_options = search.SortOptions(
expressions=[
search.SortExpression(expression='timestamp_date', default_value=0)
])
Also note that you do not need to specify direction=search.SortExpression.DESCENDING as that
is the default for direction. You do not need to specify the default value of 1000 for the limit either.

Cannot get records back from Google App Engine

I have harvested data, its not particularly clean data, and this has been bulk uploaded into the DataStore. However I am getting the following issue when trying to simply loop through all the records. I don't much care about validation at this point as all I want to do is perform a bulk operation but GAE appears not to let me even loop through the data records. I want to get at the bottom of this. To my knowledge all records have data in the field for the country and I could switch of validation, but can someone explain why this is happening and GAE is being sensitive. Thanks
result = Company.all()
my_count = result.count()
if result:
for r in result:
self.response.out.write("hello")
The data model has these properties:
class Company(db.Model):
companyurl = db.LinkProperty(required=True)
companyname = db.StringProperty(required=True)
companydesc = db.TextProperty(required=True)
companyaddress = db.PostalAddressProperty(required=False)
companypostcode = db.StringProperty(required=False)
companyemail = db.EmailProperty(required=True)
companycountry = db.StringProperty(required=True)
The error message is below
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/_webapp25.py", line 701, in __call__
handler.get(*groups)
File "/base/data/home/apps/XXX/1.358667163009710608/showcompanies.py", line 99, in get
for r in result:
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 2312, in next
return self.__model_class.from_entity(self.__iterator.next())
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 1441, in from_entity
return cls(None, _from_entity=entity, **entity_values)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 973, in __init__
prop.__set__(self, value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 613, in __set__
value = self.validate(value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 2815, in validate
value = super(StringProperty, self).validate(value)
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 640, in validate
raise BadValueError('Property %s is required' % self.name)
BadValueError: Property companycountry is required
If you have the bulk process you wish to run in its own script, you can construct a modified version of your Company class without validation. Since db.Model classes are just wrappers to the datastore based on the name of the class, you can have different classes in different parts of your code with different behaviors.
So you might have a model.py file with:
class Company(db.Model):
companyurl = db.LinkProperty(required=True)
# ...
companycountry = db.StringProperty(required=True)
# Normal operations go here
And, another bulk_process.py file with:
class Company(db.Model):
companyurl = db.LinkProperty()
# ...
companycountry = db.StringProperty()
result = Company.all()
my_count = result.count()
if result:
for r in result:
self.response.out.write("hello")
Because this second model class lacks the validation, it should run just fine. And, because the code is logically separated you don't have to worry about unintentional side-effects from removing the validation in the rest of your code. Just make sure that your bulk process doesn't accidentally write back data without validation (unless you're OK with this).

Resources