Weird encoding error when saving ActiveRecord record - ruby-on-rails-3

I have the following situation: My webservice is receiving JSON data and creating models (typical REST scenario). Sometimes I get a
Encoding::CompatibilityError Exception: incompatible character encodings: ASCII-8BIT and UTF-8
error message when saving the records, which can only be (or is) bound to two attributes. Firing up the debugger, setting ANY of those two attributes to an empty string and saving works, like so:
model = Model.new(params[:model])
model.save! # Fails with above error message
model = Model.new(params[:model])
model.attribute1 = ""
model.save! # Works
model = Model.new(params[:model])
model.attribute2 = ""
model.save! # Works too!
Now the params are parsed from the http request, how can they be dependent on each other?
Anyone with the same scenario?
Edit:
We've found the reason for the compability error: https://github.com/jruby/activerecord-jdbc-adapter/issues/229 As it seems, the JDBC adapter has some errors with utf-8 encoding, something which has been fixed for a long time in traditional rubies.

As added in the edit to my original question, the problem is a bug in the JDBC adapter of JRuby (which I forgot to add as a constraint, my bad!): https://github.com/jruby/activerecord-jdbc-adapter/issues/229

Related

Issues pulling change log using python

I am trying to query and pull changelog details using python.
The below code returns the list of issues in the project.
issued = jira.search_issues('project= proj_a', maxResults=5)
for issue in issued:
print(issue)
I am trying to pass values obtained in the issue above
issues = jira.issue(issue,expand='changelog')
changelog = issues.changelog
projects = jira.project(project)
I get the below error on trying the above:
JIRAError: JiraError HTTP 404 url: https://abc.atlassian.net/rest/api/2/issue/issue?expand=changelog
text: Issue does not exist or you do not have permission to see it.
Could anyone advise as to where am I going wrong or what permissions do I need.
Please note, if I pass a specific issue_id in the above code it works just fine but I am trying to pass a list of issue_id
You can already receive all the changelog data in the search_issues() method so you don't have to get the changelog by iterating over each issue and making another API call for each issue. Check out the code below for examples on how to work with the changelog.
issues = jira.search_issues('project= proj_a', maxResults=5, expand='changelog')
for issue in issues:
print(f"Changes from issue: {issue.key} {issue.fields.summary}")
print(f"Number of Changelog entries found: {issue.changelog.total}") # number of changelog entries (careful, each entry can have multiple field changes)
for history in issue.changelog.histories:
print(f"Author: {history.author}") # person who did the change
print(f"Timestamp: {history.created}") # when did the change happen?
print("\nListing all items that changed:")
for item in history.items:
print(f"Field name: {item.field}") # field to which the change happened
print(f"Changed to: {item.toString}") # new value, item.to might be better in some cases depending on your needs.
print(f"Changed from: {item.fromString}") # old value, item.from might be better in some cases depending on your needs.
print()
print()
Just to explain what you did wrong before when iterating over each issue: you have to use the issue.key, not the issue-resource itself. When you simply pass the issue, it won't be handled correctly as a parameter in jira.issue(). Instead, pass issue.key:
for issue in issues:
print(issue.key)
myIssue = jira.issue(issue.key, expand='changelog')

JSON Schema for FHIR false positives

I am new to JSON Schema, and am trying to validate JSON based on the HL7-FHIR schemas. Data I think should be invalid (and that the official Java-based validator says are invalid) shows up as valid.
For example, {"dog": "food"} should be invalid, because when I run the validator, I get:
> java -jar org.hl7.fhir.validator.jar bad.json -defn definitions.json.zip
.. load FHIR from definitions.json.zip
.. connect to tx server # http://tx.fhir.org/r3
(vnull-null)
.. validate
*FAILURE* validating bad.json: error:1 warn:0 info:0
Fatal # $ (line 1, col2) : Unable to find resourceType property
But if I paste the fhir.schema.json file from here into a JSON Schema validator like the one here, and evaluate {"dog": "food"}, it's valid.
It's valid even if I supply a resourceType, which I thought might cause the restrictions to kick in. It's also valid if I copy an example I expect to be valid—say, this Practitioner example—and change some of the types (set name to be a string rather than an array, for example).
I'm not sure if I'm running into a problem with the HL7-FHIR JSON Schema in particular or with JSON Schemas in general. I believe my question is different than this one because it appears that we're up to release 3.0, and so the schema I'm using is updated.

workflow task summary throwing error specified cast is not valid using spmetal layer

I have created share point data access layer with spmetal, everything is works fine but when I try to query with task summary list through SPMETAL it throws error I tried several techniques to cast , directly use this Iqueryable list but as I try to access it, "it throws error specified cast is not valid"
Any help or clue why is throwing this error
Its solved by changing the types of event type to string and duration field with double .
that error was produced by SPMETAL wrong mapping while generating the layer form SharePoint.

Loading feeds / entries getting undefined method 'entries' for 0:fixnum error

I trying to load feeds from my blog but this is resulting in the error in the title mentioned.
The error message:
NoMethodError (undefined method `entries' for 0:Fixnum):
app/controllers/pages_controller.rb:6:in `home'
This is how I'm doing:
I created a file in the libfolder called blog_feeds.rb, that contains only the following:
module BlogFeeds
require 'feedzirra'
def load_feeds
feeds = Feedzirra::Feed.fetch_and_parse('http://blog.shigotodoko.com/feed')
end
end
And the line #6 for the error is:
#feeds = load_feeds.entries
Note that this error only occurs sometimes, not always.
So, any idea about what's going wrong here?
Thank you!
When fetching a feed, Feedzirra will return the HTTP status code instead of an object containing the feed entries, if the HTTP fetch results in an error (i.e. not a 200 or 3XX).
In order to handle this condition gracefully, check the type of the object you get back from fetch_and_parse by wrapping it in something like:
unless feeds.is_a?(Fixnum)
# work with the feeds object
else
# handle the error condition, retry, etc.
end
You should also be able to see these failures by fetching the feed in a browser repeatedly, if it's frequent enough.
Well, seems that was something wrong with my code before.
I was trying to randomize some posts and using something like this on the view:
#feeds.shuffle!.first(5)
In order to get the first 5 random posts.
And to fix it, I just replaced the shuffle! method for the shufflemethod.
Now, everything is working fine!

PHP error_log errors to MySQL

In a previous ticket i asked about logging PHP errors in MySQL which gives me:
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
// mysql connect etc here...
$sql = "INSERT INTO `error_log` SET
`number` = ".mysql_real_escape_string($errno).",
`string` = ".mysql_real_escape_string($errstr).",
`file` = ".mysql_real_escape_string($errfile).",
`line` = ".mysql_real_escape_string($errline);
mysql_query($sql);
// Don't execute PHP internal error handler
return true;
}
// set to the user defined error handler
$new_error_handler = set_error_handler("myErrorHandler");
I can make this work but only if it is triggerred like this:
trigger_error("message here");
However, I also want the error handler to be called for all errors such as syntax errors like:
echo "foo;
But these errors are just outputted to the screen, what am i doing wrong?
You can only handle runtime errors with a custom error handler. The echo "foo error in your example happens when parsing (i.e. reading in) the source. Since PHP can not fully parse the code, it can also not run your error handler on this error.
If You're forced to test if syntax is correct, You can use php_check_syntax function, with filename parameter PHP Manual php_check_syntax
php_check_syntax also provides second parameter, witch when used will be populated by the error string, as far as i remember
That's indeed terrible way of error logging
You don't need not a single advantage of a database. Would you make a database lookup for the certain line number? Or order your results by file name?
database is a subject of many errors itself.
You've been told already that it's impossible to catch a parse error at the program logic level, because a syntactically wrong program will never run.
Let's take your code as an example. It will raise a MySQL error (because of poorly formed query) which you will never see. As well as any other errors occurred. That's what I am talking about.